{"id":1143491,"date":"2025-01-08T22:50:53","date_gmt":"2025-01-08T14:50:53","guid":{"rendered":""},"modified":"2025-01-08T22:50:56","modified_gmt":"2025-01-08T14:50:56","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e5%88%97%e8%a1%a8%e4%b8%ad%e4%b8%a4%e8%a1%8c%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1143491.html","title":{"rendered":"python\u5982\u4f55\u5c06\u5217\u8868\u4e2d\u4e24\u884c\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181106\/9b553853-3235-4202-9bac-490c8c1c28e9.webp\" alt=\"python\u5982\u4f55\u5c06\u5217\u8868\u4e2d\u4e24\u884c\u6570\u636e\u7c7b\u578b\" \/><\/p>\n<p><h3>\u4e00\u3001Python\u5982\u4f55\u5c06\u5217\u8868\u4e2d\u4e24\u884c\u6570\u636e\u7c7b\u578b<\/h3>\n<\/p>\n<p><p><strong>Python\u53ef\u4ee5\u901a\u8fc7\u5217\u8868\u5207\u7247\u3001\u5faa\u73af\u904d\u5386\u3001zip\u51fd\u6570\u7b49\u65b9\u6cd5\u6765\u5c06\u5217\u8868\u4e2d\u6307\u5b9a\u7684\u4e24\u884c\u6570\u636e\u7c7b\u578b\u8fdb\u884c\u8f6c\u6362<\/strong>\u3002\u5728\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u8fc7\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5bf9\u5217\u8868\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u5404\u79cd\u7c7b\u578b\u8f6c\u6362\u548c\u64cd\u4f5c\u3002\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u5c06\u5728\u672c\u6587\u4e2d\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e9b\u6280\u672f\uff0c\u5e76\u63d0\u4f9b\u5b9e\u9645\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5217\u8868\u5207\u7247\u4e0e\u7c7b\u578b\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u5207\u7247\u662fPython\u4e2d\u4e00\u4e2a\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u7528\u6765\u8bbf\u95ee\u548c\u64cd\u4f5c\u5217\u8868\u4e2d\u7684\u7279\u5b9a\u90e8\u5206\u3002\u901a\u8fc7\u5207\u7247\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u83b7\u53d6\u5217\u8868\u4e2d\u7684\u4e24\u884c\u6570\u636e\uff0c\u5e76\u5bf9\u5b83\u4eec\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h4>1. \u5217\u8868\u5207\u7247\u57fa\u7840<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u5207\u7247\u5141\u8bb8\u6211\u4eec\u4f7f\u7528\u5192\u53f7\uff08:\uff09\u6765\u6307\u5b9a\u5217\u8868\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u7d22\u5f15\uff0c\u4ece\u800c\u83b7\u53d6\u5217\u8868\u7684\u4e00\u4e2a\u5b50\u96c6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u5217\u8868<\/p>\n<p>data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/p>\n<h2><strong>\u83b7\u53d6\u5217\u8868\u4e2d\u7b2c2\u884c\u548c\u7b2c3\u884c\u7684\u6570\u636e<\/strong><\/h2>\n<p>subset = data[1:3]<\/p>\n<p>print(subset)  # \u8f93\u51fa: [2, 3]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>data[1:3]<\/code> \u83b7\u53d6\u4e86\u5217\u8868\u4e2d\u7b2c2\u884c\u548c\u7b2c3\u884c\u7684\u6570\u636e\u3002\u6ce8\u610f\uff0c\u5207\u7247\u64cd\u4f5c\u662f\u57fa\u4e8e0\u7d22\u5f15\u7684\uff0c\u56e0\u6b64\u7d22\u5f151\u8868\u793a\u5217\u8868\u7684\u7b2c\u4e8c\u4e2a\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h4>2. \u7c7b\u578b\u8f6c\u6362\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u83b7\u53d6\u5217\u8868\u4e2d\u7684\u7279\u5b9a\u884c\u6570\u636e\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u7c7b\u578b\u8f6c\u6362\u51fd\u6570\uff08\u5982 <code>int()<\/code>\u3001<code>float()<\/code>\u3001<code>str()<\/code> \u7b49\uff09\u6765\u6539\u53d8\u6570\u636e\u7c7b\u578b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u5b57\u7b26\u4e32\u7684\u5217\u8868<\/p>\n<p>data = [&#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;]<\/p>\n<h2><strong>\u83b7\u53d6\u7b2c2\u884c\u548c\u7b2c3\u884c\u7684\u6570\u636e\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b<\/strong><\/h2>\n<p>subset = data[1:3]<\/p>\n<p>subset_int = [int(i) for i in subset]<\/p>\n<p>print(subset_int)  # \u8f93\u51fa: [2, 3]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528\u5207\u7247\u64cd\u4f5c\u83b7\u53d6\u4e86\u5217\u8868\u4e2d\u7684\u7b2c2\u884c\u548c\u7b2c3\u884c\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5c06\u8fd9\u4e9b\u6570\u636e\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5faa\u73af\u904d\u5386\u4e0e\u7c7b\u578b\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5217\u8868\u5207\u7247\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5217\u8868\u4e2d\u7684\u5143\u7d20\uff0c\u5e76\u5bf9\u7279\u5b9a\u7684\u884c\u6570\u636e\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h4>1. \u5faa\u73af\u904d\u5386\u57fa\u7840<\/h4>\n<\/p>\n<p><p>\u5faa\u73af\u904d\u5386\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u7f16\u7a0b\u6280\u672f\uff0c\u7528\u4e8e\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u5217\u8868<\/p>\n<p>data = [1, 2, 3, 4, 5]<\/p>\n<h2><strong>\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20<\/strong><\/h2>\n<p>for i in data:<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>for<\/code> \u5faa\u73af\u904d\u5386\u5217\u8868 <code>data<\/code> \u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u6253\u5370\u51fa\u6765\u3002<\/p>\n<\/p>\n<p><h4>2. \u7c7b\u578b\u8f6c\u6362\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u5728\u5faa\u73af\u904d\u5386\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\u6765\u68c0\u67e5\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u5e76\u5bf9\u7279\u5b9a\u884c\u7684\u6570\u636e\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u5b57\u7b26\u4e32\u7684\u5217\u8868<\/p>\n<p>data = [&#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;]<\/p>\n<h2><strong>\u904d\u5386\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u7b2c2\u884c\u548c\u7b2c3\u884c\u7684\u6570\u636e\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b<\/strong><\/h2>\n<p>for idx, value in enumerate(data):<\/p>\n<p>    if idx == 1 or idx == 2:<\/p>\n<p>        data[idx] = int(value)<\/p>\n<p>print(data)  # \u8f93\u51fa: [&#39;1&#39;, 2, 3, &#39;4&#39;, &#39;5&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>enumerate()<\/code> \u51fd\u6570\u6765\u83b7\u53d6\u5217\u8868\u5143\u7d20\u7684\u7d22\u5f15\u548c\u503c\uff0c\u7136\u540e\u4f7f\u7528 <code>if<\/code> \u6761\u4ef6\u8bed\u53e5\u6765\u68c0\u67e5\u7d22\u5f15\u662f\u5426\u4e3a1\u62162\uff0c\u5e76\u5bf9\u8fd9\u4e9b\u884c\u7684\u6570\u636e\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528zip\u51fd\u6570\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362<\/h3>\n<\/p>\n<p><p><code>zip<\/code> \u51fd\u6570\u53ef\u4ee5\u5c06\u591a\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff08\u5982\u5217\u8868\uff09\u6253\u5305\u6210\u4e00\u4e2a\u5143\u7ec4\u7684\u8fed\u4ee3\u5668\u3002\u901a\u8fc7 <code>zip<\/code> \u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u4e24\u4e2a\u5217\u8868\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u5e76\u884c\u5904\u7406\u548c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h4>1. zip\u51fd\u6570\u57fa\u7840<\/h4>\n<\/p>\n<p><p><code>zip<\/code> \u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e24\u4e2a\u5217\u8868<\/p>\n<p>list1 = [1, 2, 3]<\/p>\n<p>list2 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]<\/p>\n<h2><strong>\u4f7f\u7528zip\u51fd\u6570\u5c06\u4e24\u4e2a\u5217\u8868\u6253\u5305\u6210\u4e00\u4e2a\u5143\u7ec4\u7684\u8fed\u4ee3\u5668<\/strong><\/h2>\n<p>zipped = zip(list1, list2)<\/p>\n<h2><strong>\u904d\u5386zipped\u4e2d\u7684\u6bcf\u4e2a\u5143\u7ec4<\/strong><\/h2>\n<p>for item in zipped:<\/p>\n<p>    print(item)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>zip(list1, list2)<\/code> \u5c06\u4e24\u4e2a\u5217\u8868\u6253\u5305\u6210\u4e00\u4e2a\u5143\u7ec4\u7684\u8fed\u4ee3\u5668\uff0c\u5e76\u5728 <code>for<\/code> \u5faa\u73af\u4e2d\u8fdb\u884c\u904d\u5386\u3002<\/p>\n<\/p>\n<p><h4>2. \u7c7b\u578b\u8f6c\u6362\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>zip<\/code> \u51fd\u6570\u5c06\u4e24\u4e2a\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u5217\u8868\u6253\u5305\u5728\u4e00\u8d77\uff0c\u5e76\u5bf9\u5176\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e24\u4e2a\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u5217\u8868<\/p>\n<p>list1 = [&#39;1&#39;, &#39;2&#39;, &#39;3&#39;]<\/p>\n<p>list2 = [&#39;4&#39;, &#39;5&#39;, &#39;6&#39;]<\/p>\n<h2><strong>\u4f7f\u7528zip\u51fd\u6570\u5c06\u4e24\u4e2a\u5217\u8868\u6253\u5305\u5728\u4e00\u8d77\uff0c\u5e76\u5bf9\u6570\u636e\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362<\/strong><\/h2>\n<p>converted_list = [(int(a), float(b)) for a, b in zip(list1, list2)]<\/p>\n<p>print(converted_list)  # \u8f93\u51fa: [(1, 4.0), (2, 5.0), (3, 6.0)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u548c <code>zip<\/code> \u51fd\u6570\u5c06\u4e24\u4e2a\u5217\u8868\u6253\u5305\u5728\u4e00\u8d77\uff0c\u5e76\u5bf9\u5176\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u4e86\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u63a2\u8ba8\u4e86\u5982\u4f55\u5728Python\u4e2d\u5c06\u5217\u8868\u4e2d\u7684\u4e24\u884c\u6570\u636e\u7c7b\u578b\u8fdb\u884c\u8f6c\u6362\u3002\u901a\u8fc7\u4f7f\u7528\u5217\u8868\u5207\u7247\u3001\u5faa\u73af\u904d\u5386\u548c <code>zip<\/code> \u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u8bbf\u95ee\u548c\u64cd\u4f5c\u5217\u8868\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><p><strong>\u5217\u8868\u5207\u7247<\/strong> \u662f\u4e00\u79cd\u7b80\u5355\u800c\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5feb\u901f\u83b7\u53d6\u5217\u8868\u4e2d\u7684\u7279\u5b9a\u90e8\u5206\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<strong>\u5faa\u73af\u904d\u5386<\/strong> \u5219\u63d0\u4f9b\u4e86\u66f4\u5927\u7684\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u5728\u904d\u5386\u8fc7\u7a0b\u4e2d\u5bf9\u7279\u5b9a\u884c\u7684\u6570\u636e\u8fdb\u884c\u5904\u7406\u3002<strong>zip\u51fd\u6570<\/strong> \u5219\u7279\u522b\u9002\u7528\u4e8e\u9700\u8981\u5e76\u884c\u5904\u7406\u591a\u4e2a\u5217\u8868\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u6280\u672f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u8fc7\u7a0b\u4e2d\u66f4\u52a0\u9ad8\u6548\u5730\u64cd\u4f5c\u548c\u8f6c\u6362\u5217\u8868\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u5e76\u4e14\u80fd\u591f\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u5217\u8868\u7684\u4e24\u884c\u6570\u636e\u8f6c\u6362\u4e3a\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5217\u8868\u7d22\u5f15\u548c\u7c7b\u578b\u8f6c\u6362\u51fd\u6570\u6765\u5b9e\u73b0\u5bf9\u5217\u8868\u4e2d\u4e24\u884c\u6570\u636e\u7c7b\u578b\u7684\u8f6c\u6362\u3002\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u591a\u79cd\u7c7b\u578b\u7684\u6570\u636e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u8bbf\u95ee\u7279\u5b9a\u7684\u884c\uff0c\u5e76\u5e94\u7528\u5982<code>int()<\/code>\u3001<code>float()<\/code>\u6216<code>str()<\/code>\u7b49\u51fd\u6570\u8fdb\u884c\u8f6c\u6362\u3002\u4f8b\u5982\uff0c<code>my_list[0] = int(my_list[0])<\/code>\u5c06\u7b2c\u4e00\u884c\u6570\u636e\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u6279\u91cf\u8f6c\u6362\u5217\u8868\u4e2d\u7279\u5b9a\u884c\u7684\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u7ed3\u5408\u6761\u4ef6\u5224\u65ad\u6765\u6279\u91cf\u8f6c\u6362\u7279\u5b9a\u884c\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u904d\u5386\u5217\u8868\uff0c\u5e76\u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d\u68c0\u67e5\u5f53\u524d\u884c\u7684\u7d22\u5f15\uff0c\u4ece\u800c\u51b3\u5b9a\u662f\u5426\u9700\u8981\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u7ecf\u8fc7\u8f6c\u6362\u7684\u6570\u636e\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u5904\u7406\u5217\u8868\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u8f6c\u6362\uff1f<\/strong><br \/>\u786e\u5b9e\u53ef\u4ee5\uff0cNumPy\u5e93\u4e3a\u6570\u7ec4\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u5904\u7406\u65b9\u5f0f\u3002\u60a8\u53ef\u4ee5\u5c06\u5217\u8868\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u5e76\u4f7f\u7528<code>astype()<\/code>\u65b9\u6cd5\u8f7b\u677e\u8f6c\u6362\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c<code>import numpy as np; my_array = np.array(my_list); my_array = my_array.astype(float)<\/code>\u5c06\u6574\u4e2a\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u5c24\u5176\u9ad8\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001Python\u5982\u4f55\u5c06\u5217\u8868\u4e2d\u4e24\u884c\u6570\u636e\u7c7b\u578b Python\u53ef\u4ee5\u901a\u8fc7\u5217\u8868\u5207\u7247\u3001\u5faa\u73af\u904d\u5386\u3001zip\u51fd\u6570\u7b49\u65b9\u6cd5\u6765\u5c06\u5217\u8868\u4e2d\u6307 [&hellip;]","protected":false},"author":3,"featured_media":1143500,"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\/1143491"}],"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=1143491"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1143491\/revisions"}],"predecessor-version":[{"id":1143502,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1143491\/revisions\/1143502"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1143500"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1143491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1143491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1143491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}