{"id":1092521,"date":"2025-01-08T14:21:56","date_gmt":"2025-01-08T06:21:56","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1092521.html"},"modified":"2025-01-08T14:21:58","modified_gmt":"2025-01-08T06:21:58","slug":"python%e5%a6%82%e4%bd%95%e6%8a%8a%e6%95%b0%e5%ad%97%e4%b8%b2%e8%bd%ac%e5%88%97%e8%a1%a8-3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1092521.html","title":{"rendered":"python\u5982\u4f55\u628a\u6570\u5b57\u4e32\u8f6c\u5217\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24205512\/cce0a8fa-c852-498c-ad8b-7cfc3a97f7cd.webp\" alt=\"python\u5982\u4f55\u628a\u6570\u5b57\u4e32\u8f6c\u5217\u8868\" \/><\/p>\n<p><p> <strong>\u8981\u5c06\u6570\u5b57\u4e32\u8f6c\u6362\u6210\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001map\u51fd\u6570\u7b49\u3002<\/strong> <\/p>\n<\/p>\n<p><p>\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\uff0c\u5c06\u6570\u5b57\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u9010\u4e2a\u8f6c\u6362\u6210\u6574\u6570\uff0c\u5e76\u5b58\u5165\u5217\u8868\u4e2d\u3002\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;12345&quot;<\/p>\n<p>num_list = [int(char) for char in num_str]<\/p>\n<p>print(num_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>num_str<\/code> \u662f\u4e00\u4e2a\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32\u3002\u901a\u8fc7\u5217\u8868\u63a8\u5bfc\u5f0f <code>[int(char) for char in num_str]<\/code>\uff0c\u6bcf\u4e2a\u5b57\u7b26\u90fd\u88ab\u8f6c\u6362\u6210\u6574\u6570\u5e76\u6dfb\u52a0\u5230 <code>num_list<\/code> \u5217\u8868\u4e2d\u3002\u6700\u7ec8\u8f93\u51fa\u7684\u7ed3\u679c\u662f <code>[1, 2, 3, 4, 5]<\/code>\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u51e0\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u6765\u5b8c\u6210\u8fd9\u4e00\u4efb\u52a1\uff0c\u5e76\u4ecb\u7ecd\u4e00\u4e9b\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b8c\u6210\u4ece\u6570\u5b57\u4e32\u5230\u5217\u8868\u7684\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;9876543210&quot;<\/p>\n<p>num_list = [int(char) for char in num_str]<\/p>\n<p>print(num_list)  # \u8f93\u51fa: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f <code>[int(char) for char in num_str]<\/code> \u904d\u5386\u4e86\u5b57\u7b26\u4e32 <code>num_str<\/code> \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\uff0c\u5c06\u5176\u8f6c\u6362\u6210\u6574\u6570\uff0c\u5e76\u6dfb\u52a0\u5230 <code>num_list<\/code> \u5217\u8868\u4e2d\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u6d01\u4e14\u9ad8\u6548\uff0c\u9002\u5408\u5904\u7406\u7b80\u5355\u7684\u6570\u5b57\u4e32\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528 map() \u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>map()<\/code> \u51fd\u6570\u662f Python \u4e2d\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u7528\u4e8e\u5c06\u4e00\u4e2a\u51fd\u6570\u5e94\u7528\u5230\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u4e0a\u3002\u53ef\u4ee5\u4f7f\u7528 <code>map()<\/code> \u51fd\u6570\u5c06\u6570\u5b57\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u8f6c\u6362\u6210\u6574\u6570\uff0c\u5e76\u5c06\u7ed3\u679c\u8f6c\u6362\u6210\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;24680&quot;<\/p>\n<p>num_list = list(map(int, num_str))<\/p>\n<p>print(num_list)  # \u8f93\u51fa: [2, 4, 6, 8, 0]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>map(int, num_str)<\/code> \u5c06 <code>num_str<\/code> \u4e2d\u7684\u6bcf\u4e2a\u5b57\u7b26\u5e94\u7528 <code>int<\/code> \u51fd\u6570\u8fdb\u884c\u8f6c\u6362\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a <code>map<\/code> \u5bf9\u8c61\u3002\u901a\u8fc7 <code>list()<\/code> \u51fd\u6570\u5c06 <code>map<\/code> \u5bf9\u8c61\u8f6c\u6362\u6210\u5217\u8868 <code>num_list<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528 for \u5faa\u73af<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u5217\u8868\u63a8\u5bfc\u5f0f\u548c <code>map()<\/code> \u51fd\u6570\u66f4\u4e3a\u7b80\u6d01\uff0c\u4f46\u6709\u65f6\u4e3a\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>for<\/code> \u5faa\u73af\u6765\u5b9e\u73b0\u8fd9\u4e00\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;13579&quot;<\/p>\n<p>num_list = []<\/p>\n<p>for char in num_str:<\/p>\n<p>    num_list.append(int(char))<\/p>\n<p>print(num_list)  # \u8f93\u51fa: [1, 3, 5, 7, 9]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>for<\/code> \u5faa\u73af\u904d\u5386 <code>num_str<\/code> \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\uff0c\u5c06\u5176\u8f6c\u6362\u6210\u6574\u6570\uff0c\u5e76\u6dfb\u52a0\u5230 <code>num_list<\/code> \u5217\u8868\u4e2d\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u7a0d\u663e\u5197\u957f\uff0c\u4f46\u5728\u4e00\u4e9b\u590d\u6742\u7684\u573a\u666f\u4e0b\u5177\u6709\u66f4\u597d\u7684\u53ef\u8bfb\u6027\u548c\u7075\u6d3b\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u7279\u6b8a\u60c5\u51b5<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6570\u5b57\u4e32\u53ef\u80fd\u5305\u542b\u4e00\u4e9b\u975e\u6570\u5b57\u5b57\u7b26\uff0c\u6216\u8005\u53ef\u80fd\u662f\u7a7a\u5b57\u7b26\u4e32\u3002\u8fd9\u65f6\u9700\u8981\u989d\u5916\u7684\u5904\u7406\uff0c\u4ee5\u786e\u4fdd\u8f6c\u6362\u8fc7\u7a0b\u4e0d\u4f1a\u51fa\u9519\u3002<\/p>\n<\/p>\n<p><h4>1. \u5904\u7406\u975e\u6570\u5b57\u5b57\u7b26<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6570\u5b57\u4e32\u4e2d\u53ef\u80fd\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fc7\u6ee4\u5668\u6216\u6761\u4ef6\u8bed\u53e5\u6765\u5904\u7406\u8fd9\u4e9b\u7279\u6b8a\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;12a34b56&quot;<\/p>\n<p>num_list = [int(char) for char in num_str if char.isdigit()]<\/p>\n<p>print(num_list)  # \u8f93\u51fa: [1, 2, 3, 4, 5, 6]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2a\u6761\u4ef6 <code>if char.isdigit()<\/code>\uff0c\u4ee5\u786e\u4fdd\u53ea\u6709\u6570\u5b57\u5b57\u7b26\u624d\u4f1a\u88ab\u8f6c\u6362\u5e76\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>2. \u5904\u7406\u7a7a\u5b57\u7b26\u4e32<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6570\u5b57\u4e32\u53ef\u80fd\u662f\u7a7a\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u5728\u8f6c\u6362\u524d\u8fdb\u884c\u68c0\u67e5\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;&quot;<\/p>\n<p>if num_str:<\/p>\n<p>    num_list = [int(char) for char in num_str]<\/p>\n<p>else:<\/p>\n<p>    num_list = []<\/p>\n<p>print(num_list)  # \u8f93\u51fa: []<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u901a\u8fc7\u68c0\u67e5 <code>num_str<\/code> \u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u786e\u4fdd\u53ea\u6709\u5728 <code>num_str<\/code> \u975e\u7a7a\u7684\u60c5\u51b5\u4e0b\u624d\u8fdb\u884c\u8f6c\u6362\uff0c\u5426\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5c06\u6570\u5b57\u4e32\u8f6c\u6362\u6210\u5217\u8868\u7684\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u7ed3\u5408\u5176\u4ed6\u6570\u636e\u5904\u7406\u4efb\u52a1\uff0c\u56e0\u6b64\u9700\u8981\u7279\u522b\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<p><h4>1. \u6570\u636e\u6e05\u6d17<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6765\u81ea\u5916\u90e8\u6765\u6e90\u7684\u6570\u636e\u65f6\uff0c\u6570\u5b57\u4e32\u4e2d\u53ef\u80fd\u5305\u542b\u4e00\u4e9b\u65e0\u6548\u6216\u5f02\u5e38\u5b57\u7b26\u3002\u9700\u8981\u5728\u8f6c\u6362\u524d\u8fdb\u884c\u6570\u636e\u6e05\u6d17\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;12,34,56&quot;<\/p>\n<p>clean_num_str = num_str.replace(&quot;,&quot;, &quot;&quot;)<\/p>\n<p>num_list = [int(char) for char in clean_num_str]<\/p>\n<p>print(num_list)  # \u8f93\u51fa: [1, 2, 3, 4, 5, 6]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528 <code>replace()<\/code> \u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u9017\u53f7\uff0c\u786e\u4fdd\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u7684\u6570\u636e\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<p><h4>2. \u6027\u80fd\u4f18\u5316<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\uff0c\u6027\u80fd\u4f18\u5316\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002\u5c3d\u91cf\u9009\u62e9\u9ad8\u6548\u7684\u65b9\u6cd5\u6765\u8fdb\u884c\u8f6c\u6362\uff0c\u4f8b\u5982\u5217\u8868\u63a8\u5bfc\u5f0f\u6216 <code>map()<\/code> \u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>num_str = &quot;1234567890&quot; * 1000000<\/p>\n<p>start_time = time.time()<\/p>\n<p>num_list = [int(char) for char in num_str]<\/p>\n<p>print(&quot;\u5217\u8868\u63a8\u5bfc\u5f0f\u7528\u65f6: &quot;, time.time() - start_time)<\/p>\n<p>start_time = time.time()<\/p>\n<p>num_list = list(map(int, num_str))<\/p>\n<p>print(&quot;map\u51fd\u6570\u7528\u65f6: &quot;, time.time() - start_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u5bf9\u6bd4\u4e0d\u540c\u65b9\u6cd5\u7684\u6267\u884c\u65f6\u95f4\uff0c\u53ef\u4ee5\u9009\u62e9\u6700\u9002\u5408\u7684\u65b9\u6848\u8fdb\u884c\u6027\u80fd\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><h4>3. \u4ee3\u7801\u53ef\u8bfb\u6027<\/h4>\n<\/p>\n<p><p>\u867d\u7136\u7b80\u6d01\u7684\u4ee3\u7801\u80fd\u591f\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\uff0c\u4f46\u5728\u56e2\u961f\u534f\u4f5c\u4e2d\uff0c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u540c\u6837\u91cd\u8981\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u4fdd\u8bc1\u4ee3\u7801\u7684\u6613\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_str = &quot;12345&quot;<\/p>\n<p>num_list = list(map(int, num_str))  # \u7b80\u6d01\u4f46\u4e0d\u6613\u8bfb<\/p>\n<p>print(num_list)<\/p>\n<p>num_list = []<\/p>\n<p>for char in num_str:  # \u9002\u4e2d\u4e14\u6613\u8bfb<\/p>\n<p>    num_list.append(int(char))<\/p>\n<p>print(num_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6839\u636e\u5b9e\u9645\u60c5\u51b5\uff0c\u5e73\u8861\u4ee3\u7801\u7b80\u6d01\u6027\u548c\u53ef\u8bfb\u6027\uff0c\u786e\u4fdd\u56e2\u961f\u534f\u4f5c\u7684\u9ad8\u6548\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5c06\u6570\u5b57\u4e32\u8f6c\u6362\u6210\u5217\u8868\u662f Python \u4e2d\u7684\u4e00\u4e2a\u5e38\u89c1\u64cd\u4f5c\uff0c\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u4efb\u52a1\u3002<strong>\u5217\u8868\u63a8\u5bfc\u5f0f\u3001map\u51fd\u6570\u3001for\u5faa\u73af<\/strong> \u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u573a\u666f\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9700\u8981\u7ed3\u5408\u5177\u4f53\u60c5\u51b5\uff0c\u9009\u62e9\u6700\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u5e76\u6ce8\u610f\u6570\u636e\u6e05\u6d17\u3001\u6027\u80fd\u4f18\u5316\u548c\u4ee3\u7801\u53ef\u8bfb\u6027\u7b49\u95ee\u9898\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u638c\u63e1\u8fd9\u4e00\u6280\u80fd\uff0c\u5e76\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u5f97\u5fc3\u5e94\u624b\u5730\u5e94\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u6570\u5217\u8868\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>map()<\/code>\u51fd\u6570\u548c<code>split()<\/code>\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u4f7f\u7528<code>split()<\/code>\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u5355\u72ec\u7684\u6570\u5b57\uff0c\u7136\u540e\u4f7f\u7528<code>map()<\/code>\u5c06\u6bcf\u4e2a\u5b57\u7b26\u4e32\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u6570\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">number_string = &quot;1 2 3 4 5&quot;\nnumber_list = list(map(int, number_string.split()))\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c<code>number_list<\/code>\u5c06\u6210\u4e3a<code>[1, 2, 3, 4, 5]<\/code>\u7684\u5f62\u5f0f\u3002<\/p>\n<p><strong>\u5728\u8f6c\u6362\u6570\u5b57\u4e32\u65f6\uff0c\u5982\u4f55\u5904\u7406\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\u7684\u60c5\u51b5\uff1f<\/strong><br \/>\u5982\u679c\u5b57\u7b26\u4e32\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\uff0c\u5efa\u8bae\u5148\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u8fc7\u6ee4\u6389\u8fd9\u4e9b\u5b57\u7b26\u3002\u53ef\u4ee5\u4f7f\u7528<code>re<\/code>\u6a21\u5757\u4e2d\u7684<code>sub()<\/code>\u51fd\u6570\u66ff\u6362\u975e\u6570\u5b57\u5b57\u7b26\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import re\nnumber_string = &quot;1, 2, 3a, 4b, 5&quot;\ncleaned_string = re.sub(r&#39;\\D+&#39;, &#39; &#39;, number_string)\nnumber_list = list(map(int, cleaned_string.split()))\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u786e\u4fdd<code>number_list<\/code>\u53ea\u5305\u542b\u6709\u6548\u7684\u6574\u6570\u3002<\/p>\n<p><strong>\u5982\u4f55\u5c06\u6570\u5b57\u4e32\u4e2d\u7684\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u5217\u8868\uff1f<\/strong><br \/>\u5982\u679c\u6570\u5b57\u4e32\u4e2d\u5305\u542b\u6d6e\u70b9\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>float()<\/code>\u51fd\u6570\u66ff\u4ee3<code>int()<\/code>\uff0c\u4ee5\u5b9e\u73b0\u8f6c\u6362\u3002\u4f7f\u7528\u65b9\u6cd5\u4e0e\u8f6c\u6362\u6574\u6570\u5217\u8868\u7c7b\u4f3c\uff0c\u53ea\u9700\u786e\u4fdd\u5b57\u7b26\u4e32\u683c\u5f0f\u6b63\u786e\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">number_string = &quot;1.1 2.2 3.3 4.4 5.5&quot;\nnumber_list = list(map(float, number_string.split()))\n<\/code><\/pre>\n<p>\u6267\u884c\u540e\uff0c<code>number_list<\/code>\u5c06\u5305\u542b<code>[1.1, 2.2, 3.3, 4.4, 5.5]<\/code>\u7684\u6d6e\u70b9\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5c06\u6570\u5b57\u4e32\u8f6c\u6362\u6210\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001map\u51fd\u6570\u7b49\u3002 \u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\uff0c\u5c06\u6570 [&hellip;]","protected":false},"author":3,"featured_media":1092524,"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\/1092521"}],"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=1092521"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1092521\/revisions"}],"predecessor-version":[{"id":1092528,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1092521\/revisions\/1092528"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1092524"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1092521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1092521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1092521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}