{"id":204146,"date":"2025-05-29T09:01:39","date_gmt":"2025-05-29T01:01:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204146\/"},"modified":"2025-05-29T09:01:39","modified_gmt":"2025-05-29T01:01:39","slug":"python-%e4%b8%ad%e5%88%97%e8%a1%a8%e6%96%b9%e6%b3%95%e5%92%8c%e5%8a%a0%e5%8f%b7%e6%93%8d%e4%bd%9c%e7%ac%a6%e5%9c%a8%e5%87%bd%e6%95%b0%e5%8f%82%e6%95%b0%e4%bc%a0%e9%80%92%e4%b8%ad%e7%9a%84%e5%b7%ae","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204146\/","title":{"rendered":"Python \u4e2d\u5217\u8868\u65b9\u6cd5\u548c\u52a0\u53f7\u64cd\u4f5c\u7b26\u5728\u51fd\u6570\u53c2\u6570\u4f20\u9012\u4e2d\u7684\u5dee\u5f02\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u4e2d\u5217\u8868\u65b9\u6cd5\u548c\u52a0\u53f7\u64cd\u4f5c\u7b26\u5728\u51fd\u6570\u53c2\u6570\u4f20\u9012\u4e2d\u7684\u5dee\u5f02\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17302091776720e5994caa3.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5217\u8868\u65b9\u6cd5\u4e0e\u52a0\u53f7\u64cd\u4f5c\u7b26\u5728\u51fd\u6570\u53c2\u6570\u4f20\u9012\u4e2d\u7684\u5dee\u5f02<\/strong><\/p>\n<p>\u5728 python \u4e2d\uff0c\u5217\u8868\u65b9\u6cd5\u548c\u52a0\u53f7\u64cd\u4f5c\u7b26\u5728\u51fd\u6570\u53c2\u6570\u4f20\u9012\u4e2d\u8868\u73b0\u51fa\u4e0d\u540c\u7684\u884c\u4e3a\u3002\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n<p>\u5728 zxc() \u51fd\u6570\u4e2d\uff0c\u5411\u5217\u8868 b \u8ffd\u52a0\u5143\u7d20\u7684 append() \u65b9\u6cd5\u76f4\u63a5\u4fee\u6539\u4e86 b \u7684\u5185\u5bb9\u3002\u56e0\u6b64\uff0c\u540e\u7eed\u8c03\u7528\u51fd\u6570\u65f6\uff0c b \u7684\u503c\u5df2\u53d1\u751f\u4e86\u53d8\u5316\u3002<\/p>\n<pre>def zxc(a, b=[]):\n    b.append(a)\n    print(b)\n\nzxc(1)  # [1]\nzxc(2)  # [1, 2]<\/pre>\n<p>\u800c\u5728 asd() \u51fd\u6570\u4e2d\uff0c\u5c06\u52a0\u53f7\u64cd\u4f5c\u7b26 + \u4e0e\u5217\u8868 [a] \u76f8\u52a0\u8fd4\u56de\u4e86\u4e00\u4e2a<strong>\u65b0\u7684\u5217\u8868<\/strong>\u3002\u56e0\u6b64\uff0c\u540e\u7eed\u8c03\u7528\u51fd\u6570\u65f6\uff0cb \u7684\u503c\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd\u3002<\/p>\n<pre>def asd(a, b=[]):\n    b = [a] + b\n    print(b)\n\nasd(1)  # [1]\nasd(2)  # [2]<\/pre>\n<p>\u8fd9\u662f\u56e0\u4e3a python \u4e2d\u7684\u5217\u8868\u662f\u53ef\u53d8\u7684\uff0c\u800c + \u64cd\u4f5c\u7b26\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u53ea\u8981\u51fa\u73b0 b = \u8bed\u53e5\uff0cb \u5c31\u4e0d\u518d\u662f\u539f\u6765\u7684 b\uff0c\u800c\u662f\u6307\u5411\u4e86\u4e00\u4e2a\u65b0\u7684\u5185\u5b58\u4f4d\u7f6e\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPython \u4e2d\u5217\u8868\u65b9\u6cd5\u548c\u52a0\u53f7\u64cd\u4f5c\u7b26\u5728\u51fd\u6570\u53c2\u6570\u4f20\u9012\u4e2d\u7684\u5dee\u5f02\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d\u5217\u8868\u65b9\u6cd5\u548c\u52a0\u53f7\u64cd&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204146","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204146"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204146\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}