{"id":204333,"date":"2025-05-29T14:20:06","date_gmt":"2025-05-29T06:20:06","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204333\/"},"modified":"2025-05-29T14:20:06","modified_gmt":"2025-05-29T06:20:06","slug":"python-%e4%b8%ad-array-%e5%92%8c-arraynone-%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204333\/","title":{"rendered":"Python \u4e2d array=[] \u548c array=None \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python \u4e2d array=[] \u548c array=None \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aPython \u4e2d array=[] \u548c array=None \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241104\/17307219886728b8c444b2b.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Python\u4e2d\u7684None<\/strong><\/p>\n<p>\u5728Python\u4e2d\uff0c<strong>array=[]<\/strong> \u548c <strong>array=None<\/strong> \u4e4b\u95f4\u5b58\u5728\u7740\u533a\u522b\u3002<\/p>\n<p><strong>array=[]<\/strong> \u521b\u5efa\u4e86\u4e00\u4e2a<strong>\u7a7a\u7684\u5217\u8868<\/strong>\uff0c\u4e5f\u5c31\u662f\u4e00\u4e2a\u4e0d\u5305\u542b\u4efb\u4f55\u5143\u7d20\u7684\u5e8f\u5217\u3002\u5b83\u662f\u4e00\u4e2a <strong>list<\/strong> \u7c7b\u578b\uff0c\u5176 <strong>len()<\/strong> \u4e3a <strong>0<\/strong>\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u5217\u8868\u65b9\u6cd5\u6765\u64cd\u4f5c\u5b83\uff0c\u4f8b\u5982\u8ffd\u52a0\u5143\u7d20\u3001\u5220\u9664\u5143\u7d20\u548c\u8bbf\u95ee\u5143\u7d20\u3002<\/p>\n<p>\u76f8\u53cd\uff0c<strong>array=None<\/strong> \u5c06\u53d8\u91cf <strong>array<\/strong> \u8bbe\u7f6e\u4e3a <strong>None<\/strong>\u3002<strong>None<\/strong> \u662f Python \u4e2d\u4e00\u79cd\u7279\u6b8a\u7684 <strong>NoneType<\/strong>\uff0c\u8868\u793a\u4e00\u4e2a<strong>\u672a\u5b9a\u4e49\u6216\u4e0d\u5b58\u5728\u7684\u503c<\/strong>\u3002\u5b83\u4e0d\u540c\u4e8e\u4e00\u4e2a\u7a7a\u7684\u5217\u8868\u6216\u5176\u4ed6\u4efb\u4f55\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b <strong>None<\/strong> \u7684\u7279\u6027\uff1a<\/p>\n<ul>\n<li><strong>len(array)<\/strong> \u4f1a\u5f15\u53d1 <strong>TypeError<\/strong>\uff0c\u56e0\u4e3a <strong>None<\/strong> \u4e0d\u662f\u4e00\u4e2a\u5e8f\u5217\u3002<\/li>\n<li>\u4f60<strong>\u65e0\u6cd5<\/strong>\u4f7f\u7528\u5217\u8868\u65b9\u6cd5\u6765\u64cd\u4f5c <strong>None<\/strong>\u3002<\/li>\n<li>\u4e0e\u5176\u4ed6\u503c\uff08\u5982\u5b57\u7b26\u4e32\u3001\u5217\u8868\u6216\u6570\u5b57\uff09\u8fdb\u884c\u6bd4\u8f83\u65f6\uff0c<strong>None<\/strong> \u603b\u4f1a\u88ab\u89c6\u4e3a <strong>False<\/strong>\u3002<\/li>\n<\/ul>\n<p>\u603b\u7684\u6765\u8bf4\uff0c<strong>array=[]<\/strong> \u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u7684\u5217\u8868\uff0c\u800c <strong>array=None<\/strong> \u5c06\u53d8\u91cf <strong>array<\/strong> \u8bbe\u7f6e\u4e3a\u4e00\u4e2a <strong>NoneType<\/strong>\uff0c\u8868\u793a\u4e00\u4e2a\u672a\u5b9a\u4e49\u6216\u4e0d\u5b58\u5728\u7684\u503c\u3002\u4e86\u89e3\u8fd9\u4e24\u8005\u4e4b\u95f4\u7684\u533a\u522b\u5bf9\u4e8e\u6709\u6548\u4f7f\u7528 Python \u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aPython \u4e2d array=[] \u548c array=None \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d array=[&#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-204333","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204333","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=204333"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204333\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}