{"id":204558,"date":"2025-05-29T13:20:56","date_gmt":"2025-05-29T05:20:56","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204558\/"},"modified":"2025-05-29T13:20:56","modified_gmt":"2025-05-29T05:20:56","slug":"python-%e4%b8%ad-append-%e5%92%8c-%e5%9c%a8%e5%87%bd%e6%95%b0%e9%bb%98%e8%ae%a4%e5%8f%82%e6%95%b0%e4%b8%ad%e7%9a%84%e8%a1%8c%e4%b8%ba%e5%b7%ae%e5%bc%82%ef%bc%9a%e4%b8%ba%e4%bb%80","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204558\/","title":{"rendered":"Python \u4e2d append \u548c \u201c+\u201d \u5728\u51fd\u6570\u9ed8\u8ba4\u53c2\u6570\u4e2d\u7684\u884c\u4e3a\u5dee\u5f02\uff1a\u4e3a\u4ec0\u4e48 append \u4f1a\u4fee\u6539\u539f\u6709\u5217\u8868\uff0c\u800c \u201c+\u201d \u5374\u521b\u5efa\u65b0\u5217\u8868\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u4e2d append \u548c \u201c+\u201d \u5728\u51fd\u6570\u9ed8\u8ba4\u53c2\u6570\u4e2d\u7684\u884c\u4e3a\u5dee\u5f02\uff1a\u4e3a\u4ec0\u4e48 append \u4f1a\u4fee\u6539\u539f\u6709\u5217\u8868\uff0c\u800c \u201c+\u201d \u5374\u521b\u5efa\u65b0\u5217\u8868\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300aPython \u4e2d append \u548c \u201c+\u201d \u5728\u51fd\u6570\u9ed8\u8ba4\u53c2\u6570\u4e2d\u7684\u884c\u4e3a\u5dee\u5f02\uff1a\u4e3a\u4ec0\u4e48 append \u4f1a\u4fee\u6539\u539f\u6709\u5217\u8868\uff0c\u800c \u201c+\u201d \u5374\u521b\u5efa\u65b0\u5217\u8868\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241110\/173123032167307a715aab1.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python \u4e2d append \u4e0e \u201c+\u201d \u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\u7684\u4e0d\u540c\u884c\u4e3a<\/strong><\/p>\n<p>\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\uff0c\u9ed8\u8ba4\u53c2\u6570\u6700\u597d\u4f7f\u7528\u4e0d\u53ef\u53d8\u5bf9\u8c61\u3002\u7136\u800c\uff0c\u5f53\u4f7f\u7528\u5217\u8868\u4f5c\u4e3a\u9ed8\u8ba4\u53c2\u6570\u65f6\uff0cappend \u65b9\u6cd5\u548c \u201c+\u201d \u5374\u8868\u73b0\u51fa\u4e86\u4e0d\u540c\u7684\u884c\u4e3a\u3002<\/p>\n<p><strong>append \u65b9\u6cd5<\/strong><\/p>\n<pre>def zxc(a, b=[]):\n    b.append(a)\n    print(b)<\/pre>\n<p>\u5728 zxc \u51fd\u6570\u4e2d\uff0cb \u4f5c\u4e3a\u53ef\u53d8\u7684\u53c2\u6570\u3002\u5982\u679c\u5728\u51fd\u6570\u8c03\u7528\u4e2d\u6ca1\u6709\u63d0\u4f9b b\uff0c\u5c06\u4f7f\u7528\u4e00\u4e2a\u7a7a\u5217\u8868\u3002\u5f53\u4f7f\u7528 append \u65b9\u6cd5\u66f4\u6539 b \u540e\uff0c\u540e\u7eed\u8c03\u7528\u51fd\u6570\u65f6\u5c06\u7ee7\u627f\u66f4\u6539\u540e\u7684 b \u503c\u3002<\/p>\n<p><strong>\u201c+\u201d \u64cd\u4f5c<\/strong><\/p>\n<pre>def asd(a, b=[]):\n    b = [a] + b\n    print(b)<\/pre>\n<p>\u5728 asd \u51fd\u6570\u4e2d\uff0c\u4e5f\u662f\u5c06 b \u4f5c\u4e3a\u53ef\u53d8\u7684\u53c2\u6570\u3002\u4f46\u5728\u4f7f\u7528 \u201c+\u201d \u64cd\u4f5c\u7b26\u65f6\uff0c\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b a \u548c b \u7684\u987a\u5e8f\u8fde\u63a5\u3002\u4e0e append \u4e0d\u540c\uff0c\u65b0\u7684\u5217\u8868\u4e0d\u4f1a\u8986\u76d6\u539f\u59cb\u7684 b\u3002<\/p>\n<p><strong>\u4e0d\u540c\u884c\u4e3a\u7684\u539f\u56e0<\/strong><\/p>\n<p>\u5728 python \u4e2d\uff0c\u53ea\u8981\u8d4b\u503c\u8bed\u53e5\u4e2d\u5305\u542b b = \uff0c\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 b \u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u5f53\u5728 asd \u51fd\u6570\u4e2d\u6267\u884c b = [a] + b \u65f6\uff0c\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u800c\u4e0d\u4f1a\u4fee\u6539\u539f\u59cb\u7684 b\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u867d\u7136 append \u548c \u201c+\u201d \u90fd\u53ef\u4ee5\u6539\u53d8\u5217\u8868\uff0c\u4f46\u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\u4f7f\u7528\u5b83\u4eec\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5b83\u4eec\u4e0d\u540c\u7684\u884c\u4e3a\u3002append \u4f1a\u4fee\u6539\u539f\u6709\u7684\u5217\u8868\u5e76\u5f71\u54cd\u540e\u7eed\u7684\u51fd\u6570\u8c03\u7528\uff0c\u800c \u201c+\u201d \u5219\u4f1a\u5728\u4e0d\u4fee\u6539\u539f\u6709\u5217\u8868\u7684\u60c5\u51b5\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5217\u8868\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aPython \u4e2d append \u548c \u201c+\u201d \u5728\u51fd\u6570\u9ed8\u8ba4\u53c2\u6570\u4e2d\u7684\u884c\u4e3a\u5dee\u5f02\uff1a\u4e3a\u4ec0\u4e48 append \u4f1a\u4fee\u6539\u539f\u6709\u5217\u8868\uff0c\u800c \u201c+\u201d \u5374\u521b\u5efa\u65b0\u5217\u8868\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d append &#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-204558","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204558","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=204558"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204558\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}