{"id":181421,"date":"2023-08-01T01:02:51","date_gmt":"2023-07-31T17:02:51","guid":{"rendered":"http:\/\/www.idc.net\/help\/181421\/"},"modified":"2023-08-01T01:02:51","modified_gmt":"2023-07-31T17:02:51","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e5%a6%82%e4%bd%95%e5%87%bd%e6%95%b0%e8%b0%83%e7%94%a8","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/181421\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u5982\u4f55\u51fd\u6570\u8c03\u7528"},"content":{"rendered":"<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/article\/000\/000\/004\/5e1e9f406d6e6653.jpg\" class=\"aligncenter\"><\/p>\n<p>\u51fd\u6570\u5b9a\u4e49\u548c\u8c03\u7528<\/p>\n<p>\u5728\u4f7f\u7528\u51fd\u6570\u4e4b\u524d\u5fc5\u987b\u5148\u5b9a\u4e49\u51fd\u6570\uff0c\u5b9a\u4e49\u51fd\u6570\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>def&nbsp;\u51fd\u6570\u540d(\u5f62\u53c2\u5217\u8868):\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u7531\u96f6\u6761\u5230\u591a\u6761\u53ef\u6267\u884c\u8bed\u53e5\u7ec4\u6210\u7684\u51fd\u6570\n&nbsp;&nbsp;&nbsp;&nbsp;[return&nbsp;[\u8fd4\u56de\u503c]]<\/pre>\n<p>Python \u58f0\u660e\u51fd\u6570\u5fc5\u987b\u4f7f\u7528 def \u5173\u952e\u5b57\uff0c\u5bf9\u51fd\u6570\u8bed\u6cd5\u683c\u5f0f\u7684\u8be6\u7ec6\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n<p>\u51fd\u6570\u540d\uff1a\u4ece\u8bed\u6cd5\u89d2\u5ea6\u6765\u770b\uff0c\u51fd\u6570\u540d\u53ea\u8981\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u6807\u8bc6\u7b26\u5373\u53ef\uff1b\u4ece\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u89d2\u5ea6\u6765\u770b\uff0c\u51fd\u6570\u540d\u5e94\u8be5\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u6709\u610f\u4e49\u7684\u5355\u8bcd\u8fde\u7f00\u800c\u6210\uff0c\u6bcf\u4e2a\u5355\u8bcd\u7684\u5b57\u6bcd\u5168\u90e8\u5c0f\u5199\uff0c\u5355\u8bcd\u4e0e\u5355\u8bcd\u4e4b\u95f4\u4f7f\u7528\u4e0b\u753b\u7ebf\u5206\u9694\u3002<\/p>\n<p>\u5f62\u53c2\u5217\u8868\uff1a\u7528\u4e8e\u5b9a\u4e49\u8be5\u51fd\u6570\u53ef\u4ee5\u63a5\u6536\u7684\u53c2\u6570\u3002\u5f62\u53c2\u5217\u8868\u7531\u591a\u4e2a\u5f62\u53c2\u540d\u7ec4\u6210\uff0c\u591a\u4e2a\u5f62\u53c2\u540d\u4e4b\u95f4\u4ee5\u82f1\u6587\u9017\u53f7\uff08,\uff09\u9694\u5f00\u3002\u4e00\u65e6\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\u6307\u5b9a\u4e86\u5f62\u53c2\u5217\u8868\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u65f6\u5c31\u5fc5\u987b\u4f20\u5165\u5230\u5e94\u7684\u53c2\u6570\u503c\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8c01\u8c03\u7528\u51fd\u6570\u8c01\u8d1f\u8d23\u4e3a\u5f62\u53c2\u8d4b\u503c\u3002<\/p>\n<p>\u5728\u51fd\u6570\u4f53\u4e2d\u591a\u6761\u53ef\u6267\u884c\u8bed\u53e5\u4e4b\u95f4\u6709\u4e25\u683c\u7684\u6267\u884c\u987a\u5e8f\uff0c\u6392\u5728\u51fd\u6570\u4f53\u524d\u9762\u7684\u8bed\u53e5\u603b\u662f\u5148\u6267\u884c\uff0c\u6392\u5728\u51fd\u6570\u4f53\u540e\u9762\u7684\u8bed\u53e5\u603b\u662f\u540e\u6267\u884c\u3002<\/p>\n<p>\u4e0b\u9762\u7a0b\u5e8f\u5b9a\u4e49\u4e86\u4e24\u4e2a\u51fd\u6570\uff0c\u4e95\u5728\u7a0b\u5e8f\u4e2d\u8c03\u7528\u5b83\u4eec\uff1a<\/p>\n<pre>#&nbsp;\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0c\u58f0\u660e2\u4e2a\u5f62\u53c2\ndef&nbsp;my_max(x,&nbsp;y)&nbsp;:\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cfz\uff0c\u8be5\u53d8\u91cf\u7b49\u4e8ex\u3001y\u4e2d\u8f83\u5927\u7684\u503c\n&nbsp;&nbsp;&nbsp;&nbsp;z&nbsp;=&nbsp;x&nbsp;if&nbsp;x&nbsp;&gt;&nbsp;y&nbsp;else&nbsp;y\n&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;\u8fd4\u56de\u53d8\u91cfz\u7684\u503c\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;z\n#&nbsp;\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0c\u58f0\u660e\u4e00\u4e2a\u5f62\u53c2\ndef&nbsp;say_hi(name)&nbsp;:\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"===\u6b63\u5728\u6267\u884csay_hi()\u51fd\u6570===\")\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;name&nbsp;+&nbsp;\"\uff0c\u60a8\u597d\uff01\"\na&nbsp;=&nbsp;6\nb&nbsp;=&nbsp;9\n#&nbsp;\u8c03\u7528my_max()\u51fd\u6570\uff0c\u5c06\u51fd\u6570\u8fd4\u56de\u503c\u8d4b\u503c\u7ed9result\u53d8\u91cf\nresult&nbsp;=&nbsp;my_max(a&nbsp;,&nbsp;b)&nbsp;#&nbsp;\u2460\nprint(\"result:\",&nbsp;result)\n#&nbsp;\u8c03\u7528say_hi()\u51fd\u6570\uff0c\u76f4\u63a5\u8f93\u51fa\u51fd\u6570\u7684\u8fd4\u56de\u503c\nprint(say_hi(\"\u5b59\u609f\u7a7a\"))&nbsp;#&nbsp;\u2461<\/pre>\n<p>\u63a8\u8350\u5b66\u4e60\u300apython\u6559\u7a0b\u300b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u51fd\u6570\u5b9a\u4e49\u548c\u8c03\u7528 \u5728\u4f7f\u7528\u51fd\u6570\u4e4b\u524d\u5fc5\u987b\u5148\u5b9a\u4e49\u51fd\u6570\uff0c\u5b9a\u4e49\u51fd\u6570\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a def&nbsp;\u51fd\u6570\u540d(\u5f62\u53c2\u5217\u8868): [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":181422,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-181421","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/181421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=181421"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/181421\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/181422"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=181421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=181421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=181421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}