{"id":204087,"date":"2025-05-29T13:40:38","date_gmt":"2025-05-29T05:40:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204087\/"},"modified":"2025-05-29T13:40:38","modified_gmt":"2025-05-29T05:40:38","slug":"python-%e5%87%bd%e6%95%b0%e5%8f%82%e6%95%b0%e9%bb%98%e8%ae%a4%e5%80%bc%ef%bc%9aappend-%e6%96%b9%e6%b3%95%e5%92%8c-%e6%93%8d%e4%bd%9c%e7%ac%a6%e7%9a%84%e5%b7%ae%e5%bc%82%e5%9c%a8%e5%93%aa%e9%87%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204087\/","title":{"rendered":"Python \u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\uff1aappend \u65b9\u6cd5\u548c + \u64cd\u4f5c\u7b26\u7684\u5dee\u5f02\u5728\u54ea\u91cc\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\uff1aappend \u65b9\u6cd5\u548c + \u64cd\u4f5c\u7b26\u7684\u5dee\u5f02\u5728\u54ea\u91cc\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730006140671dcc7ce3354.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u51fd\u6570\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\u5dee\u5f02<\/strong><\/p>\n<p>\u5728 python \u4e2d\uff0c\u5217\u8868\u7684 append \u65b9\u6cd5\u548c + \u64cd\u4f5c\u7b26\u5728\u5b9a\u4e49\u51fd\u6570\u53c2\u6570\u65f6\u8868\u73b0\u4e0d\u540c\u3002\u8fd9\u662f\u56e0\u4e3a\uff1a<\/p>\n<ul>\n<li><strong>append \u65b9\u6cd5\uff1a<\/strong>append \u65b9\u6cd5\u4f1a\u4fee\u6539\u539f\u5217\u8868\uff0c\u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u672b\u5c3e\u3002\u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\uff0c\u5982\u679c\u9ed8\u8ba4\u53c2\u6570\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u5217\u8868\uff0c\u5e76\u4e14\u591a\u6b21\u8c03\u7528\u8be5\u51fd\u6570\uff0c\u5219\u9ed8\u8ba4\u53c2\u6570\u4f1a\u7d2f\u79ef\u6b64\u524d\u6240\u6709\u51fd\u6570\u8c03\u7528\u4e2d\u6dfb\u52a0\u7684\u5143\u7d20\u3002<\/li>\n<li><strong>+ \u64cd\u4f5c\u7b26\uff1a<\/strong>+ \u64cd\u4f5c\u7b26\u4e0d\u4f1a\u4fee\u6539\u539f\u5217\u8868\uff0c\u800c\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u5217\u8868\uff0c\u5e76\u5c06\u539f\u5217\u8868\u548c\u65b0\u5143\u7d20\u5408\u5e76\u3002\u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\uff0c\u5982\u679c\u9ed8\u8ba4\u53c2\u6570\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u5217\u8868\uff0c\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u5305\u542b\u65b0\u5143\u7d20\u548c\u539f\u5148\u7684\u9ed8\u8ba4\u53c2\u6570\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u8fd9\u4e00\u70b9\uff1a<\/p>\n<pre>def zxc(a, b=[]):\n    b.append(a)\n    print(b)\n\nzxc(1)  # [1]\nzxc(2)  # [1, 2]\n\ndef asd(a, b=[]):\n    b = [a] + b\n    print(b)\n\nasd(1)  # [1]\nasd(2)  # [2]<\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre>[1]\n[1, 2]\n[1]\n[2]<\/pre>\n<p>\u5728 zxc \u51fd\u6570\u4e2d\uff0c\u9ed8\u8ba4\u53c2\u6570 b=[] \u4f1a\u7d2f\u79ef\u6b64\u524d\u8c03\u7528\u4e2d\u6dfb\u52a0\u7684\u5143\u7d20\u3002\u800c\u5728 asd \u51fd\u6570\u4e2d\uff0c\u6bcf\u6b21\u8c03\u7528\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 b \u5217\u8868\uff0c\u4e0d\u4f1a\u53d7\u5230\u6b64\u524d\u8c03\u7528\u5f71\u54cd\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPython \u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\uff1aappend \u65b9\u6cd5\u548c + \u64cd\u4f5c\u7b26\u7684\u5dee\u5f02\u5728\u54ea\u91cc\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\uff1aa&#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-204087","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204087","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=204087"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204087\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}