{"id":2684,"date":"2025-05-28T17:13:48","date_gmt":"2025-06-04T09:54:47","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=2684"},"modified":"2025-06-04T17:13:48","modified_gmt":"2025-06-04T09:54:47","slug":"%e4%bd%bf%e7%94%a8list%e5%87%bd%e6%95%b8%e5%b0%87%e5%85%b6%e4%bb%96%e8%b3%87%e6%96%99%e7%b5%90%e6%a7%8b%e8%bd%89%e6%8f%9b%e7%82%bapython%e4%b8%b2%e5%88%97","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/python\/%e4%bd%bf%e7%94%a8list%e5%87%bd%e6%95%b8%e5%b0%87%e5%85%b6%e4%bb%96%e8%b3%87%e6%96%99%e7%b5%90%e6%a7%8b%e8%bd%89%e6%8f%9b%e7%82%bapython%e4%b8%b2%e5%88%97\/","title":{"rendered":"2025 \u6700\u65b0 Python \u7a0b\u5f0f\u6559\u5b78\uff1a\u4f7f\u7528 list() \u51fd\u6578\u5c07\u5176\u4ed6\u8cc7\u6599\u7d50\u69cb\u8f49\u63db\u70ba\u4e32\u5217"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Python, \u4e32\u5217, List, \u8cc7\u6599\u7d50\u69cb, \u8f49\u63db, Python \u6559\u5b78, Python 2025\"><\/p>\n<h1>2025 \u6700\u65b0 Python \u7a0b\u5f0f\u6559\u5b78\uff1a\u4f7f\u7528 list() \u51fd\u6578\u5c07\u5176\u4ed6\u8cc7\u6599\u7d50\u69cb\u8f49\u63db\u70ba\u4e32\u5217<\/h1>\n<p>Python \u4e32\u5217\uff08List\uff09\u662f\u4e00\u7a2e\u5ee3\u6cdb\u61c9\u7528\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u53ef\u4ee5\u5132\u5b58\u591a\u500b\u5143\u7d20\u4e26\u9032\u884c\u5404\u7a2e\u64cd\u4f5c\u3002\u900f\u904e\u5167\u5efa\u7684 `list()` \u51fd\u6578\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5c07\u5176\u4ed6\u8cc7\u6599\u7d50\u69cb\uff08\u4f8b\u5982\u5143\u7d44\u3001\u5b57\u5178\u3001\u5b57\u4e32\u7b49\uff09\u8f49\u63db\u70ba\u4e32\u5217\uff0c\u9019\u5728\u8655\u7406\u8cc7\u6599\u6642\u975e\u5e38\u4fbf\u5229\u3002<\/p>\n<p>## \u4f7f\u7528 list() \u51fd\u6578\u7684\u57fa\u672c\u8a9e\u6cd5<\/p>\n<p>`list()` \u51fd\u6578\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;`python<br \/>\nlist(iterable)<br \/>\n&#8220;`<\/p>\n<p>\u9019\u88e1\u7684 `iterable` \u53ef\u4ee5\u662f\u4efb\u4f55\u53ef\u8fed\u4ee3\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u5982\u5143\u7d44\u3001\u5b57\u5178\u6216\u5b57\u4e32\u7b49\u3002<\/p>\n<p>## \u5be6\u4f5c\u7bc4\u4f8b<\/p>\n<p>### \u7bc4\u4f8b\u4e00\uff1a\u5c07\u5143\u7d44\u8f49\u63db\u70ba\u4e32\u5217<\/p>\n<p>\u4ee5\u4e0b\u7bc4\u4f8b\u5c55\u793a\u5982\u4f55\u5c07\u5143\u7d44 `(1, 2, 3, 4, 5)` \u8f49\u63db\u70ba\u4e32\u5217\uff1a<\/p>\n<p>&#8220;`python<br \/>\n# \u5b9a\u7fa9\u5143\u7d44<br \/>\nmy_tuple = (1, 2, 3, 4, 5)<\/p>\n<p># \u5c07\u5143\u7d44\u8f49\u63db\u70ba\u4e32\u5217<br \/>\nlist_from_tuple = list(my_tuple)<\/p>\n<p># \u5370\u51fa\u4e32\u5217<br \/>\nprint(list_from_tuple)<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\uff1a<\/p>\n<p>&#8220;`<br \/>\n[1, 2, 3, 4, 5]\n&#8220;`<\/p>\n<p>### \u7bc4\u4f8b\u4e8c\uff1a\u5c07\u5b57\u5178\u8f49\u63db\u70ba\u4e32\u5217<\/p>\n<p>\u63a5\u4e0b\u4f86\u7684\u7bc4\u4f8b\u5c07\u5b57\u5178 `{&#8216;name&#8217;: &#8216;John&#8217;, &#8216;age&#8217;: 20}` \u8f49\u63db\u70ba\u4e32\u5217\uff1a<\/p>\n<p>&#8220;`python<br \/>\n# \u5b9a\u7fa9\u5b57\u5178<br \/>\nmy_dict = {&#8216;name&#8217;: &#8216;John&#8217;, &#8216;age&#8217;: 20}<\/p>\n<p># \u5c07\u5b57\u5178\u7684\u9375\u8f49\u63db\u70ba\u4e32\u5217<br \/>\nlist_from_dict = list(my_dict)<\/p>\n<p># \u5370\u51fa\u4e32\u5217<br \/>\nprint(list_from_dict)<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\uff1a<\/p>\n<p>&#8220;`<br \/>\n[&#8216;name&#8217;, &#8216;age&#8217;]\n&#8220;`<\/p>\n<p>### \u7bc4\u4f8b\u4e09\uff1a\u5c07\u5b57\u4e32\u8f49\u63db\u70ba\u4e32\u5217<\/p>\n<p>\u6700\u5f8c\uff0c\u770b\u770b\u5982\u4f55\u5c07\u5b57\u4e32 `&#8221;Hello World&#8221;` \u8f49\u63db\u70ba\u4e32\u5217\uff1a<\/p>\n<p>&#8220;`python<br \/>\n# \u5b9a\u7fa9\u5b57\u4e32<br \/>\nmy_string = &#8220;Hello World&#8221;<\/p>\n<p># \u5c07\u5b57\u4e32\u8f49\u63db\u70ba\u4e32\u5217<br \/>\nlist_from_string = list(my_string)<\/p>\n<p># \u5370\u51fa\u4e32\u5217<br \/>\nprint(list_from_string)<br \/>\n&#8220;`<\/p>\n<p>\u57f7\u884c\u7d50\u679c\uff1a<\/p>\n<p>&#8220;`<br \/>\n[&#8216;H&#8217;, &#8216;e&#8217;, &#8216;l&#8217;, &#8216;l&#8217;, &#8216;o&#8217;, &#8216; &#8216;, &#8216;W&#8217;, &#8216;o&#8217;, &#8216;r&#8217;, &#8216;l&#8217;, &#8216;d&#8217;]\n&#8220;`<\/p>\n<p>## \u932f\u8aa4\u6392\u9664<\/p>\n<p>\u5728\u4f7f\u7528 `list()` \u51fd\u6578\u6642\uff0c\u8acb\u78ba\u4fdd\u50b3\u5165\u7684\u53c3\u6578\u662f\u53ef\u8fed\u4ee3\u7684\u8cc7\u6599\u7d50\u69cb\u3002\u82e5\u50b3\u5165\u7684\u53c3\u6578\u4e0d\u662f\u53ef\u8fed\u4ee3\u5c0d\u8c61\uff0c\u5c07\u6703\u5f15\u767c `TypeError`\u3002\u4f8b\u5982\uff1a<\/p>\n<p>&#8220;`python<br \/>\n# \u932f\u8aa4\u7bc4\u4f8b<br \/>\nnumber = 12345<br \/>\nlist_from_number = list(number)  # \u9019\u88e1\u6703\u5f15\u767c TypeError<br \/>\n&#8220;`<\/p>\n<p>## \u5ef6\u4f38\u61c9\u7528<\/p>\n<p>\u8f49\u63db\u8cc7\u6599\u7d50\u69cb\u70ba\u4e32\u5217\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e32\u5217\u7684\u5404\u7a2e\u65b9\u6cd5\u9032\u884c\u8cc7\u6599\u8655\u7406\uff0c\u4f8b\u5982\u6392\u5e8f\u3001\u6dfb\u52a0\u6216\u522a\u9664\u5143\u7d20\u7b49\u3002\u9019\u4f7f\u5f97\u4e32\u5217\u6210\u70ba Python \u4e2d\u975e\u5e38\u9748\u6d3b\u4e14\u5f37\u5927\u7684\u8cc7\u6599\u7d50\u69cb\u3002<\/p>\n<p>\u5982\u9700\u9032\u4e00\u6b65\u4e86\u89e3 Python \u7684\u4e32\u5217\u53ca\u5176\u61c9\u7528\uff0c\u60a8\u53ef\u4ee5\u53c3\u8003\u9019\u7bc7 [Python \u4e32\u5217\u6559\u5b78](https:\/\/vocus.cc) \u7372\u53d6\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n<p>## Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/p>\n<p>**Q1: list() \u51fd\u6578\u53ef\u4ee5\u8f49\u63db\u54ea\u4e9b\u8cc7\u6599\u985e\u578b\uff1f**<br \/>\nA1: `list()` \u51fd\u6578\u53ef\u4ee5\u8f49\u63db\u5143\u7d44\u3001\u5b57\u5178\u3001\u5b57\u4e32\u53ca\u5176\u4ed6\u53ef\u8fed\u4ee3\u7684\u8cc7\u6599\u985e\u578b\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u5c07\u5b57\u5178\u7684\u503c\u8f49\u63db\u70ba\u4e32\u5217\uff1f**<br \/>\nA2: \u60a8\u53ef\u4ee5\u4f7f\u7528 `list(my_dict.values())` \u5c07\u5b57\u5178\u7684\u503c\u8f49\u63db\u70ba\u4e32\u5217\u3002<\/p>\n<p>**Q3: \u5728\u4f7f\u7528 list() \u51fd\u6578\u6642\uff0c\u6709\u4ec0\u9ebc\u5e38\u898b\u932f\u8aa4\uff1f**<br \/>\nA3: \u6700\u5e38\u898b\u7684\u932f\u8aa4\u662f\u50b3\u5165\u4e00\u500b\u4e0d\u53ef\u8fed\u4ee3\u7684\u7269\u4ef6\uff0c\u4f8b\u5982\u6574\u6578\uff0c\u9019\u6703\u5f15\u767c `TypeError`\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528list()\u51fd\u6578\u53ef\u4ee5\u5c07\u5176\u4ed6\u8cc7\u6599\u7d50\u69cb\u8f49\u63db\u70baPython\u4e32\u5217\uff0c\u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u7387\u5730\u8655\u7406\u8cc7\u6599\u3002\u672c\u6587\u5c07\u4ecb\u7d39list()\u51fd\u6578\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5982\u4f55\u5c07\u5176\u4ed6\u8cc7\u6599\u7d50\u69cb\u8f49\u63db\u70baPython\u4e32\u5217\u3002<\/p>\n","protected":false},"author":1,"featured_media":2518,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18],"tags":[15],"class_list":["post-2684","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2022\/12\/DALL\u00b7E-2022-12-28-14.25.55-\u62f7\u8c9d2.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-Hi","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/2684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=2684"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/2684\/revisions"}],"predecessor-version":[{"id":13046,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/2684\/revisions\/13046"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/2518"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=2684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=2684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=2684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}