{"id":1093813,"date":"2025-01-08T14:34:50","date_gmt":"2025-01-08T06:34:50","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1093813.html"},"modified":"2025-01-08T14:34:54","modified_gmt":"2025-01-08T06:34:54","slug":"python%e5%a6%82%e4%bd%95%e7%94%a8%e5%85%83%e7%bb%84%e5%ad%98%e5%82%a8%e5%ad%97%e7%ac%a6%e4%b8%b2-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1093813.html","title":{"rendered":"python\u5982\u4f55\u7528\u5143\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210226\/0259f82a-005b-477d-b932-1d0700bcff1e.webp\" alt=\"python\u5982\u4f55\u7528\u5143\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u4f7f\u7528\u5143\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\u3001\u4fbf\u4e8e\u7ef4\u62a4\u3001\u4e0d\u53ef\u53d8\u3001\u9002\u5408\u9700\u8981\u56fa\u5b9a\u6570\u636e\u7ed3\u6784\u7684\u573a\u666f\u3002<\/strong> \u5143\u7ec4\u4e0e\u5217\u8868\u7c7b\u4f3c\uff0c\u4f46\u4e0d\u540c\u70b9\u5728\u4e8e\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u5373\u5143\u7ec4\u4e00\u65e6\u521b\u5efa\uff0c\u5176\u5185\u5bb9\u5c31\u4e0d\u80fd\u518d\u66f4\u6539\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u5143\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u5b9e\u7528\u7684\u793a\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5143\u7ec4\u7684\u5b9a\u4e49\u4e0e\u57fa\u672c\u4f7f\u7528<\/h3>\n<\/p>\n<p><p>\u5143\u7ec4\u662fPython\u4e2d\u7684\u4e00\u79cd\u5185\u5efa\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u591a\u4e2a\u6570\u636e\u9879\u3002\u4e0e\u5217\u8868\u7c7b\u4f3c\uff0c\u5143\u7ec4\u4f7f\u7528\u5706\u62ec\u53f7<code>()<\/code>\u6765\u5b9a\u4e49\uff0c\u800c\u5217\u8868\u4f7f\u7528\u65b9\u62ec\u53f7<code>[]<\/code>\u3002\u5143\u7ec4\u53ef\u4ee5\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b9a\u4e49\u5143\u7ec4<\/h4>\n<\/p>\n<p><p>\u5b9a\u4e49\u4e00\u4e2a\u5143\u7ec4\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5c06\u6570\u636e\u9879\u7528\u9017\u53f7\u5206\u9694\uff0c\u5e76\u653e\u5728\u5706\u62ec\u53f7\u4e2d\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u5b57\u7b26\u4e32\u7684\u5143\u7ec4<\/p>\n<p>my_tuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)<\/p>\n<p>print(my_tuple)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8bbf\u95ee\u5143\u7ec4\u5143\u7d20<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u6765\u8bbf\u95ee\u5143\u7ec4\u4e2d\u7684\u5143\u7d20\uff0c\u7d22\u5f15\u4ece0\u5f00\u59cb\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bbf\u95ee\u5143\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20<\/p>\n<p>print(my_tuple[0])  # \u8f93\u51fa &quot;apple&quot;<\/p>\n<h2><strong>\u8bbf\u95ee\u5143\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20<\/strong><\/h2>\n<p>print(my_tuple[-1])  # \u8f93\u51fa &quot;cherry&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u5143\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32\u7684\u4f18\u52bf<\/h3>\n<\/p>\n<p><h4>1\u3001\u4e0d\u53ef\u53d8\u6027<\/h4>\n<\/p>\n<p><p>\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4e00\u65e6\u521b\u5efa\u4e86\u5143\u7ec4\uff0c\u5176\u5185\u5bb9\u5c31\u4e0d\u80fd\u66f4\u6539\u3002\u8fd9\u79cd\u7279\u6027\u4f7f\u5143\u7ec4\u975e\u5e38\u9002\u5408\u5b58\u50a8\u90a3\u4e9b\u4e0d\u9700\u8981\u66f4\u6539\u7684\u6570\u636e\uff0c\u786e\u4fdd\u6570\u636e\u7684\u5b89\u5168\u6027\u548c\u4e00\u81f4\u6027\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u6027\u80fd\u4f18\u5316<\/h4>\n<\/p>\n<p><p>\u7531\u4e8e\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u56e0\u6b64\u5b83\u4eec\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u5229\u7528\u5185\u5b58\u548c\u5904\u7406\u901f\u5ea6\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u5143\u7ec4\u53ef\u4ee5\u63d0\u5347\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u9002\u5408\u4f5c\u4e3a\u5b57\u5178\u952e<\/h4>\n<\/p>\n<p><p>\u56e0\u4e3a\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u6240\u4ee5\u5b83\u4eec\u53ef\u4ee5\u4f5c\u4e3a\u5b57\u5178\u7684\u952e\uff0c\u800c\u5217\u8868\u4e0d\u80fd\u3002\u8fd9\u5728\u9700\u8981\u5c06\u591a\u7ef4\u6570\u636e\u6620\u5c04\u5230\u5355\u4e2a\u503c\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5143\u7ec4\u7684\u9ad8\u7ea7\u64cd\u4f5c<\/h3>\n<\/p>\n<p><h4>1\u3001\u5143\u7ec4\u89e3\u5305<\/h4>\n<\/p>\n<p><p>\u5143\u7ec4\u89e3\u5305\u662f\u4e00\u79cd\u5c06\u5143\u7ec4\u4e2d\u7684\u5143\u7d20\u8d4b\u503c\u7ed9\u591a\u4e2a\u53d8\u91cf\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5143\u7ec4\u89e3\u5305<\/p>\n<p>fruit1, fruit2, fruit3 = my_tuple<\/p>\n<p>print(fruit1)  # \u8f93\u51fa &quot;apple&quot;<\/p>\n<p>print(fruit2)  # \u8f93\u51fa &quot;banana&quot;<\/p>\n<p>print(fruit3)  # \u8f93\u51fa &quot;cherry&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u548c\u6613\u8bfb\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5d4c\u5957\u5143\u7ec4<\/h4>\n<\/p>\n<p><p>\u5143\u7ec4\u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5143\u7ec4\uff0c\u8fd9\u79f0\u4e3a\u5d4c\u5957\u5143\u7ec4\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u5d4c\u5957\u5143\u7ec4<\/p>\n<p>nested_tuple = ((&quot;apple&quot;, &quot;banana&quot;), (&quot;cherry&quot;, &quot;date&quot;))<\/p>\n<p>print(nested_tuple)<\/p>\n<h2><strong>\u8bbf\u95ee\u5d4c\u5957\u5143\u7ec4\u7684\u5143\u7d20<\/strong><\/h2>\n<p>print(nested_tuple[0][1])  # \u8f93\u51fa &quot;banana&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5143\u7ec4\u5207\u7247<\/h4>\n<\/p>\n<p><p>\u4e0e\u5217\u8868\u7c7b\u4f3c\uff0c\u5143\u7ec4\u4e5f\u652f\u6301\u5207\u7247\u64cd\u4f5c\u3002\u901a\u8fc7\u5207\u7247\uff0c\u53ef\u4ee5\u83b7\u53d6\u5143\u7ec4\u7684\u4e00\u4e2a\u5b50\u96c6\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5143\u7ec4\u5207\u7247<\/p>\n<p>print(my_tuple[1:3])  # \u8f93\u51fa (&quot;banana&quot;, &quot;cherry&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5207\u7247\u64cd\u4f5c\u4e0d\u4f1a\u4fee\u6539\u539f\u5143\u7ec4\uff0c\u800c\u662f\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><h4>1\u3001\u5b58\u50a8\u56fa\u5b9a\u914d\u7f6e<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u5b58\u50a8\u4e00\u4e9b\u56fa\u5b9a\u7684\u914d\u7f6e\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u5728\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4\u4e0d\u4f1a\u66f4\u6539\u3002\u5143\u7ec4\u662f\u5b58\u50a8\u8fd9\u4e9b\u6570\u636e\u7684\u7406\u60f3\u9009\u62e9\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b58\u50a8\u6570\u636e\u5e93\u914d\u7f6e\u4fe1\u606f<\/p>\n<p>db_config = (&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, &quot;my_database&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u51fd\u6570\u8fd4\u56de\u591a\u4e2a\u503c<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u5728\u8fd4\u56de\u591a\u4e2a\u503c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5143\u7ec4\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def get_user_info():<\/p>\n<p>    # \u8fd4\u56de\u7528\u6237\u7684\u59d3\u540d\u548c\u5e74\u9f84<\/p>\n<p>    return (&quot;John Doe&quot;, 30)<\/p>\n<p>name, age = get_user_info()<\/p>\n<p>print(name)  # \u8f93\u51fa &quot;John Doe&quot;<\/p>\n<p>print(age)  # \u8f93\u51fa 30<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u591a\u7ef4\u6570\u636e\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u591a\u7ef4\u6570\u636e\u65f6\uff0c\u5143\u7ec4\u53ef\u4ee5\u7528\u4e8e\u5b58\u50a8\u5750\u6807\u3001\u5411\u91cf\u7b49\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b58\u50a8\u4e8c\u7ef4\u5750\u6807<\/p>\n<p>point = (10, 20)<\/p>\n<p>print(point)<\/p>\n<h2><strong>\u5b58\u50a8\u4e09\u7ef4\u5750\u6807<\/strong><\/h2>\n<p>vector = (1, 2, 3)<\/p>\n<p>print(vector)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5143\u7ec4\u4e0e\u5217\u8868\u7684\u6bd4\u8f83<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u5143\u7ec4\u548c\u5217\u8868\u90fd\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u591a\u4e2a\u6570\u636e\u9879\uff0c\u4f46\u5b83\u4eec\u5728\u7279\u6027\u548c\u4f7f\u7528\u573a\u666f\u4e0a\u6709\u4e00\u4e9b\u533a\u522b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u53ef\u53d8\u6027<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u662f\u53ef\u53d8\u7684\uff0c\u53ef\u4ee5\u4fee\u6539\u3001\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\uff1b\u800c\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u4fee\u6539\u3002\u8fd9\u4f7f\u5f97\u5143\u7ec4\u5728\u9700\u8981\u4fdd\u6301\u6570\u636e\u4e0d\u53d8\u65f6\u66f4\u52a0\u9002\u7528\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u6027\u80fd<\/h4>\n<\/p>\n<p><p>\u7531\u4e8e\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7684\uff0cPython\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u4f18\u5316\uff0c\u4f7f\u5176\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u6bd4\u5217\u8868\u66f4\u9ad8\u6548\u3002\u5982\u679c\u6027\u80fd\u662f\u5173\u952e\u56e0\u7d20\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u9002\u7528\u573a\u666f<\/h4>\n<\/p>\n<ul>\n<li>\u5217\u8868\u9002\u7528\u4e8e\u9700\u8981\u9891\u7e41\u4fee\u6539\u6570\u636e\u7684\u573a\u666f\uff0c\u4f8b\u5982\u52a8\u6001\u6570\u7ec4\u3002<\/li>\n<li>\u5143\u7ec4\u9002\u7528\u4e8e\u6570\u636e\u4e0d\u9700\u8981\u4fee\u6539\u7684\u573a\u666f\uff0c\u4f8b\u5982\u914d\u7f6e\u6570\u636e\u3001\u591a\u7ef4\u6570\u636e\u3001\u51fd\u6570\u8fd4\u56de\u503c\u7b49\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><h4>1\u3001\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784<\/h4>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u4f7f\u7528\u5143\u7ec4\u8fd8\u662f\u5217\u8868\u65f6\uff0c\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u573a\u666f\u8fdb\u884c\u9009\u62e9\u3002\u5982\u679c\u6570\u636e\u9700\u8981\u4fee\u6539\uff0c\u4f7f\u7528\u5217\u8868\uff1b\u5982\u679c\u6570\u636e\u4e0d\u9700\u8981\u4fee\u6539\uff0c\u4f7f\u7528\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5408\u7406\u4f7f\u7528\u5143\u7ec4\u89e3\u5305<\/h4>\n<\/p>\n<p><p>\u5143\u7ec4\u89e3\u5305\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u548c\u6613\u8bfb\uff0c\u4f46\u5728\u4f7f\u7528\u65f6\u5e94\u786e\u4fdd\u5143\u7ec4\u7684\u957f\u5ea6\u548c\u53d8\u91cf\u6570\u91cf\u5339\u914d\uff0c\u5426\u5219\u4f1a\u5f15\u53d1\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u907f\u514d\u5d4c\u5957\u8fc7\u6df1<\/h4>\n<\/p>\n<p><p>\u867d\u7136\u5143\u7ec4\u652f\u6301\u5d4c\u5957\uff0c\u4f46\u5d4c\u5957\u8fc7\u6df1\u4f1a\u4f7f\u4ee3\u7801\u96be\u4ee5\u7ef4\u62a4\u3002\u5e94\u5c3d\u91cf\u4fdd\u6301\u6570\u636e\u7ed3\u6784\u7684\u7b80\u5355\u548c\u6e05\u6670\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5143\u7ec4\u662fPython\u4e2d\u4e00\u79cd\u975e\u5e38\u6709\u7528\u7684\u6570\u636e\u7ed3\u6784\uff0c\u9002\u5408\u5b58\u50a8\u56fa\u5b9a\u4e0d\u53d8\u7684\u6570\u636e\u3002\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u8bfb\u8005\u5e94\u8be5\u5bf9\u5982\u4f55\u4f7f\u7528\u5143\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32\u6709\u4e86\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5408\u7406\u9009\u62e9\u548c\u4f7f\u7528\u5143\u7ec4\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u6027\u80fd\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u60a8\u5728Python\u7f16\u7a0b\u4e2d\u53d6\u5f97\u66f4\u5927\u7684\u8fdb\u6b65\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5143\u7ec4\u5728Python\u4e2d\u6709\u4ec0\u4e48\u4f18\u52bf\uff0c\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u5b57\u7b26\u4e32\u5417\uff1f<\/strong><br \/>\u5143\u7ec4\u662fPython\u4e2d\u7684\u4e00\u79cd\u5185\u7f6e\u6570\u636e\u7c7b\u578b\uff0c\u5177\u6709\u4e0d\u53ef\u53d8\u6027\u548c\u6709\u5e8f\u6027\u3002\u7531\u4e8e\u5143\u7ec4\u7684\u4e0d\u53ef\u53d8\u7279\u6027\uff0c\u5b83\u4eec\u5728\u5b58\u50a8\u5b57\u7b26\u4e32\u65f6\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u4e0d\u88ab\u610f\u5916\u4fee\u6539\u3002\u5143\u7ec4\u7684\u5b58\u50a8\u6548\u7387\u4e5f\u901a\u5e38\u6bd4\u5217\u8868\u66f4\u9ad8\uff0c\u9002\u5408\u5b58\u50a8\u4e00\u7ec4\u76f8\u5173\u7684\u5b57\u7b26\u4e32\u6570\u636e\uff0c\u6bd4\u5982\u5e38\u91cf\u503c\u6216\u4e0d\u9700\u8981\u4fee\u6539\u7684\u914d\u7f6e\u9879\u3002<\/p>\n<p><strong>\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b57\u7b26\u4e32\u7684\u5143\u7ec4\uff1f<\/strong><br \/>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u5b57\u7b26\u4e32\u7684\u5143\u7ec4\u975e\u5e38\u7b80\u5355\u3002\u53ea\u9700\u5c06\u5b57\u7b26\u4e32\u7528\u9017\u53f7\u5206\u9694\uff0c\u5e76\u7528\u5706\u62ec\u53f7\u62ec\u8d77\u6765\u5373\u53ef\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u8fd9\u6837\u521b\u5efa\u4e00\u4e2a\u5143\u7ec4\uff1a<code>my_tuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)<\/code>\u3002\u8bbf\u95ee\u5143\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\u4e0e\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5143\u7d20\u76f8\u4f3c\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\uff0c\u5982 <code>my_tuple[0]<\/code> \u5c06\u8fd4\u56de <code>&quot;apple&quot;<\/code>\u3002<\/p>\n<p><strong>\u5143\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\u53ef\u4ee5\u8fdb\u884c\u54ea\u4e9b\u64cd\u4f5c\uff1f<\/strong><br \/>\u867d\u7136\u5143\u7ec4\u672c\u8eab\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u4f46\u5b58\u50a8\u5728\u5143\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\u53ef\u4ee5\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u4f8b\u5982\u62fc\u63a5\u3001\u5207\u7247\u548c\u641c\u7d22\u3002\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u65b9\u6cd5\uff0c\u5982 <code>my_tuple[0].upper()<\/code> \u5c06\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\uff0c\u6216\u8005\u4f7f\u7528 <code>len(my_tuple)<\/code> \u83b7\u53d6\u5143\u7ec4\u4e2d\u5b57\u7b26\u4e32\u7684\u6570\u91cf\u3002\u6b64\u5916\uff0c\u5982\u679c\u9700\u8981\u4fee\u6539\u5143\u7ec4\u4e2d\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5143\u7ec4\uff0c\u5305\u542b\u4fee\u6539\u540e\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u4f7f\u7528\u5143\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\u3001\u4fbf\u4e8e\u7ef4\u62a4\u3001\u4e0d\u53ef\u53d8\u3001\u9002\u5408\u9700\u8981\u56fa\u5b9a\u6570\u636e\u7ed3\u6784\u7684\u573a\u666f\u3002 \u5143\u7ec4\u4e0e\u5217\u8868 [&hellip;]","protected":false},"author":3,"featured_media":1093821,"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\/1093813"}],"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=1093813"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1093813\/revisions"}],"predecessor-version":[{"id":1093823,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1093813\/revisions\/1093823"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1093821"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1093813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1093813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1093813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}