{"id":1080662,"date":"2025-01-08T12:32:16","date_gmt":"2025-01-08T04:32:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1080662.html"},"modified":"2025-01-08T12:32:18","modified_gmt":"2025-01-08T04:32:18","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%85%83%e7%bb%84%e5%92%8c%e5%88%97%e8%a1%a8%e7%9a%84%e8%bd%ac%e6%8d%a2-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1080662.html","title":{"rendered":"python\u5982\u4f55\u5b9e\u73b0\u5143\u7ec4\u548c\u5217\u8868\u7684\u8f6c\u6362"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183057\/01829204-a8d7-4b83-b236-cb9e52234ad4.webp\" alt=\"python\u5982\u4f55\u5b9e\u73b0\u5143\u7ec4\u548c\u5217\u8868\u7684\u8f6c\u6362\" \/><\/p>\n<p><p> <strong>Python\u4e2d\u5143\u7ec4\u548c\u5217\u8868\u7684\u8f6c\u6362\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u51fd\u6570\u8fdb\u884c\uff0c\u4f8b\u5982\u4f7f\u7528 <code>tuple()<\/code> \u51fd\u6570\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4\uff0c\u4f7f\u7528 <code>list()<\/code> \u51fd\u6570\u5c06\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4<\/p>\n<p>\u4f7f\u7528 <code>tuple()<\/code> \u51fd\u6570\u53ef\u4ee5\u5c06\u4e00\u4e2a\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3]<\/p>\n<p>my_tuple = tuple(my_list)<\/p>\n<p>print(my_tuple)  # \u8f93\u51fa: (1, 2, 3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/p>\n<p>\u4f7f\u7528 <code>list()<\/code> \u51fd\u6570\u53ef\u4ee5\u5c06\u4e00\u4e2a\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_tuple = (1, 2, 3)<\/p>\n<p>my_list = list(my_tuple)<\/p>\n<p>print(my_list)  # \u8f93\u51fa: [1, 2, 3]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u8f6c\u6362\u65b9\u6cd5\uff0c\u5e76\u5217\u4e3e\u51fa\u76f8\u5173\u7684\u5e94\u7528\u573a\u666f\u548c\u5b9e\u4f8b\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528 <code>tuple()<\/code> \u51fd\u6570<\/h4>\n<\/p>\n<p><p><code>tuple()<\/code> \u662fPython\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5143\u7ec4\u3002\u5217\u8868\u5c31\u662f\u4e00\u79cd\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u4f20\u7ed9 <code>tuple()<\/code> \u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4]<\/p>\n<p>my_tuple = tuple(my_list)<\/p>\n<p>print(my_tuple)  # \u8f93\u51fa: (1, 2, 3, 4)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4\u540e\uff0c\u6570\u636e\u5c06\u4e0d\u53ef\u53d8\uff0c\u4ece\u800c\u589e\u5f3a\u4e86\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<ul>\n<li><strong>\u4e0d\u5e0c\u671b\u6570\u636e\u88ab\u4fee\u6539<\/strong>\uff1a\u6709\u65f6\u5019\u6570\u636e\u9700\u8981\u4fdd\u6301\u4e0d\u53d8\uff0c\u5982\u6570\u636e\u5e93\u8fde\u63a5\u53c2\u6570\u3001\u914d\u7f6e\u6587\u4ef6\u5185\u5bb9\u7b49\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528\u5143\u7ec4\u3002<\/li>\n<li><strong>\u4f5c\u4e3a\u5b57\u5178\u7684\u952e<\/strong>\uff1a\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4f5c\u4e3a\u5b57\u5178\u7684\u952e\uff0c\u800c\u5217\u8868\u4e0d\u80fd\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528 <code>list()<\/code> \u51fd\u6570<\/h4>\n<\/p>\n<p><p><code>list()<\/code> \u662fPython\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5217\u8868\u3002\u5143\u7ec4\u4e5f\u662f\u4e00\u79cd\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u4f20\u7ed9 <code>list()<\/code> \u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_tuple = (1, 2, 3, 4)<\/p>\n<p>my_list = list(my_tuple)<\/p>\n<p>print(my_list)  # \u8f93\u51fa: [1, 2, 3, 4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\u540e\uff0c\u6570\u636e\u53ef\u4ee5\u88ab\u4fee\u6539\uff0c\u589e\u52a0\u4e86\u6570\u636e\u7684\u7075\u6d3b\u6027\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5e94\u7528\u573a\u666f<\/h4>\n<\/p>\n<ul>\n<li><strong>\u9700\u8981\u4fee\u6539\u6570\u636e<\/strong>\uff1a\u5f53\u6570\u636e\u9700\u8981\u88ab\u4fee\u6539\u65f6\uff0c\u53ef\u4ee5\u5c06\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\u3002<\/li>\n<li><strong>\u5217\u8868\u7684\u64cd\u4f5c<\/strong>\uff1a\u5217\u8868\u652f\u6301\u8bb8\u591a\u5143\u7ec4\u4e0d\u652f\u6301\u7684\u64cd\u4f5c\uff0c\u5982\u6dfb\u52a0\u3001\u5220\u9664\u3001\u6392\u5e8f\u7b49\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9879<\/h3>\n<\/p>\n<p><h4>1\u3001\u6570\u636e\u7c7b\u578b\u7684\u53d8\u5316<\/h4>\n<\/p>\n<p><p>\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u8981\u6ce8\u610f\u6570\u636e\u7c7b\u578b\u7684\u53d8\u5316\u3002\u4f8b\u5982\uff0c\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4\u540e\uff0c\u4e0d\u518d\u652f\u6301\u5217\u8868\u7684\u4fee\u6539\u64cd\u4f5c\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3]<\/p>\n<p>my_tuple = tuple(my_list)<\/p>\n<h2><strong>my_tuple[0] = 4  # \u8fd9\u884c\u4ee3\u7801\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u5143\u7ec4\u4e0d\u652f\u6301\u4fee\u6539\u64cd\u4f5c<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6df1\u62f7\u8d1d\u548c\u6d45\u62f7\u8d1d<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u8f6c\u6362\u65f6\uff0c\u5982\u679c\u5217\u8868\u6216\u5143\u7ec4\u4e2d\u5305\u542b\u5176\u4ed6\u53ef\u53d8\u5bf9\u8c61\uff08\u5982\u5217\u8868\u3001\u5b57\u5178\u7b49\uff09\uff0c\u8981\u6ce8\u610f\u6df1\u62f7\u8d1d\u548c\u6d45\u62f7\u8d1d\u7684\u95ee\u9898\u3002\u6d45\u62f7\u8d1d\u4f1a\u590d\u5236\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u800c\u6df1\u62f7\u8d1d\u4f1a\u590d\u5236\u5bf9\u8c61\u53ca\u5176\u5305\u542b\u7684\u6240\u6709\u5bf9\u8c61\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import copy<\/p>\n<p>my_list = [1, [2, 3], 4]<\/p>\n<p>my_tuple = tuple(my_list)<\/p>\n<p>my_list[1][0] = 99<\/p>\n<p>print(my_tuple)  # \u8f93\u51fa: (1, [99, 3], 4)\uff0c\u8bf4\u660e\u662f\u6d45\u62f7\u8d1d<\/p>\n<p>my_list = [1, [2, 3], 4]<\/p>\n<p>my_tuple = tuple(copy.deepcopy(my_list))<\/p>\n<p>my_list[1][0] = 99<\/p>\n<p>print(my_tuple)  # \u8f93\u51fa: (1, [2, 3], 4)\uff0c\u8bf4\u660e\u662f\u6df1\u62f7\u8d1d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5b9e\u7528\u6848\u4f8b<\/h3>\n<\/p>\n<p><h4>1\u3001\u4ece\u6587\u4ef6\u8bfb\u53d6\u6570\u636e\u5e76\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u6709\u4e00\u4e2a\u5305\u542b\u914d\u7f6e\u53c2\u6570\u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>host=127.0.0.1<\/p>\n<p>port=3306<\/p>\n<p>user=root<\/p>\n<p>password=123456<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\uff0c\u5c06\u5176\u5b58\u50a8\u4e3a\u5217\u8868\u6216\u5143\u7ec4\uff0c\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u8f6c\u6362\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9<\/p>\n<p>with open(&#39;config.txt&#39;, &#39;r&#39;) as file:<\/p>\n<p>    lines = file.readlines()<\/p>\n<h2><strong>\u5c06\u6587\u4ef6\u5185\u5bb9\u8f6c\u6362\u4e3a\u5b57\u5178<\/strong><\/h2>\n<p>config = {}<\/p>\n<p>for line in lines:<\/p>\n<p>    key, value = line.strip().split(&#39;=&#39;)<\/p>\n<p>    config[key] = value<\/p>\n<h2><strong>\u5c06\u5b57\u5178\u7684\u952e\u548c\u503c\u5206\u522b\u8f6c\u6362\u4e3a\u5143\u7ec4<\/strong><\/h2>\n<p>keys_tuple = tuple(config.keys())<\/p>\n<p>values_tuple = tuple(config.values())<\/p>\n<p>print(keys_tuple)  # \u8f93\u51fa: (&#39;host&#39;, &#39;port&#39;, &#39;user&#39;, &#39;password&#39;)<\/p>\n<p>print(values_tuple)  # \u8f93\u51fa: (&#39;127.0.0.1&#39;, &#39;3306&#39;, &#39;root&#39;, &#39;123456&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u5e93\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5c06\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3a\u5217\u8868\u6216\u5143\u7ec4\u3002<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;example.db&#39;)<\/p>\n<p>cursor = conn.cursor()<\/p>\n<h2><strong>\u521b\u5efa\u8868<\/strong><\/h2>\n<p>cursor.execute(&#39;CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)&#39;)<\/p>\n<h2><strong>\u63d2\u5165\u6570\u636e<\/strong><\/h2>\n<p>cursor.execute(&#39;INSERT INTO users (name, age) VALUES (?, ?)&#39;, (&#39;Alice&#39;, 25))<\/p>\n<p>cursor.execute(&#39;INSERT INTO users (name, age) VALUES (?, ?)&#39;, (&#39;Bob&#39;, 30))<\/p>\n<p>conn.commit()<\/p>\n<h2><strong>\u67e5\u8be2\u6570\u636e<\/strong><\/h2>\n<p>cursor.execute(&#39;SELECT * FROM users&#39;)<\/p>\n<p>rows = cursor.fetchall()<\/p>\n<h2><strong>\u5c06\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>rows_list = list(rows)<\/p>\n<p>print(rows_list)  # \u8f93\u51fa: [(1, &#39;Alice&#39;, 25), (2, &#39;Bob&#39;, 30)]<\/p>\n<h2><strong>\u5c06\u67e5\u8be2\u7ed3\u679c\u8f6c\u6362\u4e3a\u5143\u7ec4<\/strong><\/h2>\n<p>rows_tuple = tuple(rows)<\/p>\n<p>print(rows_tuple)  # \u8f93\u51fa: ((1, &#39;Alice&#39;, 25), (2, &#39;Bob&#39;, 30))<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>cursor.close()<\/p>\n<p>conn.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u6027\u80fd\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u5927\u89c4\u6a21\u6570\u636e\u5904\u7406\u65f6\uff0c\u5217\u8868\u548c\u5143\u7ec4\u7684\u6027\u80fd\u5dee\u5f02\u53ef\u80fd\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\u3002\u5143\u7ec4\u7531\u4e8e\u4e0d\u53ef\u53d8\uff0c\u901a\u5e38\u5728\u521b\u5efa\u548c\u8bbf\u95ee\u65f6\u6bd4\u5217\u8868\u66f4\u5feb\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u65f6\u95f4\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import timeit<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b100\u4e07\u4e2a\u5143\u7d20\u7684\u5217\u8868<\/strong><\/h2>\n<p>list_time = timeit.timeit(&#39;list(range(1000000))&#39;, number=1000)<\/p>\n<p>print(&#39;\u521b\u5efa\u5217\u8868\u7684\u65f6\u95f4:&#39;, list_time)<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b100\u4e07\u4e2a\u5143\u7d20\u7684\u5143\u7ec4<\/strong><\/h2>\n<p>tuple_time = timeit.timeit(&#39;tuple(range(1000000))&#39;, number=1000)<\/p>\n<p>print(&#39;\u521b\u5efa\u5143\u7ec4\u7684\u65f6\u95f4:&#39;, tuple_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8bbf\u95ee\u65f6\u95f4\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import timeit<\/p>\n<h2><strong>\u521b\u5efa\u5305\u542b100\u4e07\u4e2a\u5143\u7d20\u7684\u5217\u8868\u548c\u5143\u7ec4<\/strong><\/h2>\n<p>my_list = list(range(1000000))<\/p>\n<p>my_tuple = tuple(range(1000000))<\/p>\n<h2><strong>\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5143\u7d20<\/strong><\/h2>\n<p>list_access_time = timeit.timeit(&#39;my_list[500000]&#39;, globals=globals(), number=1000000)<\/p>\n<p>print(&#39;\u8bbf\u95ee\u5217\u8868\u5143\u7d20\u7684\u65f6\u95f4:&#39;, list_access_time)<\/p>\n<h2><strong>\u8bbf\u95ee\u5143\u7ec4\u4e2d\u7684\u5143\u7d20<\/strong><\/h2>\n<p>tuple_access_time = timeit.timeit(&#39;my_tuple[500000]&#39;, globals=globals(), number=1000000)<\/p>\n<p>print(&#39;\u8bbf\u95ee\u5143\u7ec4\u5143\u7d20\u7684\u65f6\u95f4:&#39;, tuple_access_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5217\u8868\u548c\u5143\u7ec4\u7684\u8f6c\u6362\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684 <code>list()<\/code> \u548c <code>tuple()<\/code> \u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002\u5217\u8868\u9002\u7528\u4e8e\u9700\u8981\u9891\u7e41\u4fee\u6539\u6570\u636e\u7684\u573a\u666f\uff0c\u800c\u5143\u7ec4\u9002\u7528\u4e8e\u6570\u636e\u9700\u8981\u4fdd\u6301\u4e0d\u53d8\u7684\u573a\u666f\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528\u5185\u7f6e\u7684<code>tuple()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4\u3002\u53ea\u9700\u5c06\u5217\u8868\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u8fd9\u4e2a\u51fd\u6570\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u5373\u4e3a\u5bf9\u5e94\u7684\u5143\u7ec4\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">my_list = [1, 2, 3]\nmy_tuple = tuple(my_list)\nprint(my_tuple)  # \u8f93\u51fa: (1, 2, 3)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u7b80\u4fbf\uff0c\u9002\u7528\u4e8e\u4efb\u4f55\u7c7b\u578b\u7684\u5217\u8868\u3002<\/p>\n<p><strong>\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u8fc7\u7a0b\u662f\u600e\u6837\u7684\uff1f<\/strong><br \/>\u8981\u5c06\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528<code>list()<\/code>\u51fd\u6570\u3002\u5c06\u5143\u7ec4\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\uff0c\u4fbf\u4f1a\u5f97\u5230\u76f8\u5e94\u7684\u5217\u8868\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">my_tuple = (1, 2, 3)\nmy_list = list(my_tuple)\nprint(my_list)  # \u8f93\u51fa: [1, 2, 3]\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u8f6c\u6362\u540c\u6837\u7b80\u5355\uff0c\u9002\u5408\u5404\u79cd\u7c7b\u578b\u7684\u5143\u7ec4\u3002<\/p>\n<p><strong>\u5728\u8f6c\u6362\u65f6\u4f1a\u4e22\u5931\u6570\u636e\u5417\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u5143\u7ec4\u4e0e\u5217\u8868\u7684\u8f6c\u6362\u8fc7\u7a0b\u4e2d\uff0c\u6570\u636e\u4e0d\u4f1a\u4e22\u5931\u3002\u8fd9\u4e24\u79cd\u6570\u636e\u7ed3\u6784\u7684\u5143\u7d20\u90fd\u4f1a\u5b8c\u6574\u4fdd\u7559\u3002\u8f6c\u6362\u53ea\u662f\u6539\u53d8\u4e86\u6570\u636e\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u800c\u5217\u8868\u662f\u53ef\u53d8\u7684\u3002\u56e0\u6b64\uff0c\u8f6c\u6362\u540e\uff0c\u539f\u59cb\u6570\u636e\u4ecd\u7136\u4fdd\u6301\u4e0d\u53d8\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u5143\u7ec4\u548c\u5217\u8868\u7684\u8f6c\u6362\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u51fd\u6570\u8fdb\u884c\uff0c\u4f8b\u5982\u4f7f\u7528 tuple() \u51fd\u6570\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5143\u7ec4\uff0c\u4f7f\u7528 li [&hellip;]","protected":false},"author":3,"featured_media":1080671,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1080662"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1080662"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1080662\/revisions"}],"predecessor-version":[{"id":1080673,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1080662\/revisions\/1080673"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1080671"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1080662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1080662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1080662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}