{"id":1161466,"date":"2025-01-13T19:16:43","date_gmt":"2025-01-13T11:16:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1161466.html"},"modified":"2025-01-13T19:16:45","modified_gmt":"2025-01-13T11:16:45","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e4%be%9d%e6%ac%a1%e8%be%93%e5%85%a5%e5%a4%9a%e4%b8%aa","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1161466.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u4f9d\u6b21\u8f93\u5165\u591a\u4e2a"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25202726\/e2bbeadb-f604-4e7a-be8a-b57d56adcdee.webp\" alt=\"python\u4e2d\u5982\u4f55\u4f9d\u6b21\u8f93\u5165\u591a\u4e2a\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u4f9d\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5982\u4f7f\u7528input\u51fd\u6570\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u5faa\u73af\u7b49\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<\/strong>\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528input\u51fd\u6570\u9010\u4e2a\u8f93\u5165\u3001\u4f7f\u7528split\u51fd\u6570\u4e00\u6b21\u6027\u8f93\u5165\u591a\u4e2a\u503c\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u8fdb\u884c\u6279\u91cf\u5904\u7406\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u89e3\u91ca\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528split\u51fd\u6570\u4e00\u6b21\u6027\u8f93\u5165\u591a\u4e2a\u503c\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u65b9\u6cd5\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2ainput\u51fd\u6570\u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u4f7f\u7528split\u65b9\u6cd5\u5c06\u5176\u5206\u5272\u6210\u591a\u4e2a\u503c\u3002split\u65b9\u6cd5\u9ed8\u8ba4\u6309\u7a7a\u683c\u5206\u5272\uff0c\u4e5f\u53ef\u4ee5\u6307\u5b9a\u5176\u4ed6\u5206\u9694\u7b26\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u7528\u6237\u4e00\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u60c5\u51b5\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u4e32<\/p>\n<p>input_string = input(&quot;\u8bf7\u8f93\u5165\u591a\u4e2a\u503c\uff0c\u4ee5\u7a7a\u683c\u5206\u9694: &quot;)<\/p>\n<h2><strong>\u4f7f\u7528split\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u591a\u4e2a\u503c\uff0c\u5b58\u5165\u5217\u8868<\/strong><\/h2>\n<p>values = input_string.split()<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>print(&quot;\u8f93\u5165\u7684\u591a\u4e2a\u503c\u4e3a:&quot;, values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e00\u3001\u9010\u4e2a\u8f93\u5165\u591a\u4e2a\u503c<\/h3>\n<\/p>\n<p><p>\u9010\u4e2a\u8f93\u5165\u591a\u4e2a\u503c\u662f\u6700\u7b80\u5355\u76f4\u89c2\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u9700\u8981\u7528\u6237\u9010\u4e00\u786e\u8ba4\u8f93\u5165\u7684\u60c5\u51b5\u3002\u53ef\u4ee5\u5728\u5faa\u73af\u4e2d\u591a\u6b21\u8c03\u7528input\u51fd\u6570\uff0c\u6bcf\u6b21\u8bfb\u53d6\u4e00\u4e2a\u503c\u5e76\u5b58\u5165\u5217\u8868\u6216\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u7a7a\u5217\u8868\u5b58\u50a8\u8f93\u5165\u7684\u503c<\/p>\n<p>values = []<\/p>\n<h2><strong>\u8bbe\u7f6e\u9700\u8981\u8f93\u5165\u7684\u503c\u7684\u4e2a\u6570<\/strong><\/h2>\n<p>n = int(input(&quot;\u8bf7\u8f93\u5165\u9700\u8981\u8f93\u5165\u7684\u503c\u7684\u4e2a\u6570: &quot;))<\/p>\n<h2><strong>\u4f7f\u7528\u5faa\u73af\u9010\u4e2a\u8f93\u5165\u503c<\/strong><\/h2>\n<p>for i in range(n):<\/p>\n<p>    value = input(f&quot;\u8bf7\u8f93\u5165\u7b2c{i+1}\u4e2a\u503c: &quot;)<\/p>\n<p>    values.append(value)<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>print(&quot;\u8f93\u5165\u7684\u591a\u4e2a\u503c\u4e3a:&quot;, values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u76f4\u89c2\uff0c\u4f46\u8f93\u5165\u591a\u4e2a\u503c\u65f6\u9700\u8981\u591a\u6b21\u8c03\u7528input\u51fd\u6570\uff0c\u7528\u6237\u4f53\u9a8c\u53ef\u80fd\u4e0d\u5982\u4e00\u6b21\u6027\u8f93\u5165\u597d\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528split\u51fd\u6570\u4e00\u6b21\u6027\u8f93\u5165\u591a\u4e2a\u503c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528split\u51fd\u6570\u4e00\u6b21\u6027\u8f93\u5165\u591a\u4e2a\u503c\u53ef\u4ee5\u63d0\u9ad8\u8f93\u5165\u6548\u7387\uff0c\u9002\u7528\u4e8e\u7528\u6237\u53ef\u4ee5\u4e00\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u4e32<\/p>\n<p>input_string = input(&quot;\u8bf7\u8f93\u5165\u591a\u4e2a\u503c\uff0c\u4ee5\u7a7a\u683c\u5206\u9694: &quot;)<\/p>\n<h2><strong>\u4f7f\u7528split\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u591a\u4e2a\u503c\uff0c\u5b58\u5165\u5217\u8868<\/strong><\/h2>\n<p>values = input_string.split()<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>print(&quot;\u8f93\u5165\u7684\u591a\u4e2a\u503c\u4e3a:&quot;, values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9ad8\u6548\u7b80\u6d01\uff0c\u9002\u7528\u4e8e\u7528\u6237\u4e00\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u60c5\u51b5\uff0c\u4f46\u4e0d\u9002\u7528\u4e8e\u9700\u8981\u9010\u4e00\u786e\u8ba4\u8f93\u5165\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5904\u7406\u8f93\u5165\u503c<\/h3>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u9ad8\u6548\u7684\u5904\u7406\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5bf9\u8f93\u5165\u503c\u8fdb\u884c\u4e00\u5b9a\u5904\u7406\u6216\u8f6c\u6362\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u4e32<\/p>\n<p>input_string = input(&quot;\u8bf7\u8f93\u5165\u591a\u4e2a\u6574\u6570\u503c\uff0c\u4ee5\u7a7a\u683c\u5206\u9694: &quot;)<\/p>\n<h2><strong>\u4f7f\u7528split\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u591a\u4e2a\u503c\uff0c\u5e76\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5c06\u5176\u8f6c\u6362\u4e3a\u6574\u6570<\/strong><\/h2>\n<p>values = [int(x) for x in input_string.split()]<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>print(&quot;\u8f93\u5165\u7684\u591a\u4e2a\u503c\u4e3a:&quot;, values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u6d01\u9ad8\u6548\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5bf9\u8f93\u5165\u503c\u8fdb\u884c\u5904\u7406\u6216\u8f6c\u6362\u7684\u60c5\u51b5\uff0c\u4f46\u5bf9\u4e8e\u590d\u6742\u7684\u8f93\u5165\u9700\u6c42\u53ef\u80fd\u4e0d\u591f\u7075\u6d3b\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5faa\u73af\u548c\u6761\u4ef6\u5224\u65ad\u5904\u7406\u590d\u6742\u8f93\u5165<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u590d\u6742\u7684\u8f93\u5165\u9700\u6c42\uff0c\u53ef\u4ee5\u7ed3\u5408\u5faa\u73af\u548c\u6761\u4ef6\u5224\u65ad\u8fdb\u884c\u5904\u7406\u3002\u4f8b\u5982\uff0c\u9700\u8981\u8f93\u5165\u591a\u4e2a\u503c\u5e76\u5bf9\u6bcf\u4e2a\u503c\u8fdb\u884c\u9a8c\u8bc1\u6216\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u7a7a\u5217\u8868\u5b58\u50a8\u8f93\u5165\u7684\u503c<\/p>\n<p>values = []<\/p>\n<h2><strong>\u8bbe\u7f6e\u9700\u8981\u8f93\u5165\u7684\u503c\u7684\u4e2a\u6570<\/strong><\/h2>\n<p>n = int(input(&quot;\u8bf7\u8f93\u5165\u9700\u8981\u8f93\u5165\u7684\u503c\u7684\u4e2a\u6570: &quot;))<\/p>\n<h2><strong>\u4f7f\u7528\u5faa\u73af\u9010\u4e2a\u8f93\u5165\u503c\u5e76\u8fdb\u884c\u9a8c\u8bc1\u6216\u5904\u7406<\/strong><\/h2>\n<p>for i in range(n):<\/p>\n<p>    while True:<\/p>\n<p>        value = input(f&quot;\u8bf7\u8f93\u5165\u7b2c{i+1}\u4e2a\u6574\u6570\u503c: &quot;)<\/p>\n<p>        try:<\/p>\n<p>            # \u5c1d\u8bd5\u5c06\u8f93\u5165\u503c\u8f6c\u6362\u4e3a\u6574\u6570<\/p>\n<p>            int_value = int(value)<\/p>\n<p>            values.append(int_value)<\/p>\n<p>            break<\/p>\n<p>        except ValueError:<\/p>\n<p>            print(&quot;\u8f93\u5165\u7684\u503c\u65e0\u6548\uff0c\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570\u3002&quot;)<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>print(&quot;\u8f93\u5165\u7684\u591a\u4e2a\u503c\u4e3a:&quot;, values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7075\u6d3b\u6027\u9ad8\uff0c\u9002\u7528\u4e8e\u590d\u6742\u7684\u8f93\u5165\u9700\u6c42\uff0c\u4f46\u4ee3\u7801\u8f83\u4e3a\u7e41\u7410\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u51fd\u6570\u5c01\u88c5\u8f93\u5165\u903b\u8f91<\/h3>\n<\/p>\n<p><p>\u5c06\u8f93\u5165\u903b\u8f91\u5c01\u88c5\u5230\u51fd\u6570\u4e2d\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u548c\u53ef\u8bfb\u6027\u3002\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5b9a\u4e49\u4e0d\u540c\u7684\u8f93\u5165\u51fd\u6570\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u8f93\u5165\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def input_multiple_values(prompt, n):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u8f93\u5165\u591a\u4e2a\u503c\u7684\u51fd\u6570<\/p>\n<p>    \u53c2\u6570:<\/p>\n<p>    prompt -- \u8f93\u5165\u63d0\u793a\u4fe1\u606f<\/p>\n<p>    n -- \u9700\u8981\u8f93\u5165\u7684\u503c\u7684\u4e2a\u6570<\/p>\n<p>    \u8fd4\u56de\u503c:<\/p>\n<p>    values -- \u8f93\u5165\u7684\u503c\u7684\u5217\u8868<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    values = []<\/p>\n<p>    for i in range(n):<\/p>\n<p>        value = input(f&quot;{prompt} \u7b2c{i+1}\u4e2a\u503c: &quot;)<\/p>\n<p>        values.append(value)<\/p>\n<p>    return values<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\u8f93\u5165\u591a\u4e2a\u503c<\/strong><\/h2>\n<p>n = int(input(&quot;\u8bf7\u8f93\u5165\u9700\u8981\u8f93\u5165\u7684\u503c\u7684\u4e2a\u6570: &quot;))<\/p>\n<p>values = input_multiple_values(&quot;\u8bf7\u8f93\u5165&quot;, n)<\/p>\n<h2><strong>\u8f93\u51fa\u7ed3\u679c<\/strong><\/h2>\n<p>print(&quot;\u8f93\u5165\u7684\u591a\u4e2a\u503c\u4e3a:&quot;, values)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u590d\u7528\u6027\u548c\u53ef\u8bfb\u6027\uff0c\u9002\u7528\u4e8e\u9700\u8981\u591a\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u7efc\u5408\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u7efc\u5408\u5e94\u7528\u4ee5\u4e0a\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528split\u51fd\u6570\u548c\u5217\u8868\u63a8\u5bfc\u5f0f\u8fdb\u884c\u4e00\u6b21\u6027\u8f93\u5165\u548c\u5904\u7406\uff0c\u4e5f\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\u5faa\u73af\u548c\u6761\u4ef6\u5224\u65ad\u8fdb\u884c\u590d\u6742\u8f93\u5165\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def input_and_process_values():<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u8f93\u5165\u548c\u5904\u7406\u591a\u4e2a\u503c\u7684\u51fd\u6570<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    # \u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u4e32<\/p>\n<p>    input_string = input(&quot;\u8bf7\u8f93\u5165\u591a\u4e2a\u6574\u6570\u503c\uff0c\u4ee5\u7a7a\u683c\u5206\u9694: &quot;)<\/p>\n<p>    # \u4f7f\u7528split\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u591a\u4e2a\u503c\uff0c\u5e76\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5c06\u5176\u8f6c\u6362\u4e3a\u6574\u6570<\/p>\n<p>    values = [int(x) for x in input_string.split()]<\/p>\n<p>    # \u8f93\u51fa\u7ed3\u679c<\/p>\n<p>    print(&quot;\u8f93\u5165\u7684\u591a\u4e2a\u503c\u4e3a:&quot;, values)<\/p>\n<p>    # \u5bf9\u8f93\u5165\u7684\u503c\u8fdb\u884c\u5904\u7406\uff0c\u4f8b\u5982\u6c42\u548c<\/p>\n<p>    total = sum(values)<\/p>\n<p>    print(&quot;\u8f93\u5165\u7684\u503c\u7684\u603b\u548c\u4e3a:&quot;, total)<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570\u8f93\u5165\u548c\u5904\u7406\u591a\u4e2a\u503c<\/strong><\/h2>\n<p>input_and_process_values()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7efc\u5408\u4e86\u591a\u79cd\u8f93\u5165\u548c\u5904\u7406\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u591a\u79cd\u8f93\u5165\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4f9d\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\u9009\u62e9\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u9010\u4e2a\u8f93\u5165\u9002\u7528\u4e8e\u9700\u8981\u9010\u4e00\u786e\u8ba4\u8f93\u5165\u7684\u60c5\u51b5\uff0c\u4f7f\u7528split\u51fd\u6570\u4e00\u6b21\u6027\u8f93\u5165\u9002\u7528\u4e8e\u7528\u6237\u53ef\u4ee5\u4e00\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u60c5\u51b5\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5904\u7406\u8f93\u5165\u503c\u9002\u7528\u4e8e\u9700\u8981\u5bf9\u8f93\u5165\u503c\u8fdb\u884c\u5904\u7406\u6216\u8f6c\u6362\u7684\u60c5\u51b5\uff0c\u4f7f\u7528\u5faa\u73af\u548c\u6761\u4ef6\u5224\u65ad\u5904\u7406\u590d\u6742\u8f93\u5165\u9002\u7528\u4e8e\u590d\u6742\u7684\u8f93\u5165\u9700\u6c42\uff0c\u5c06\u8f93\u5165\u903b\u8f91\u5c01\u88c5\u5230\u51fd\u6570\u4e2d\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u548c\u53ef\u8bfb\u6027\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u7efc\u5408\u5e94\u7528\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u8f93\u5165\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8f93\u5165\u591a\u4e2a\u503c\u5e76\u5b58\u50a8\u5230\u5217\u8868\u4e2d\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u63a5\u6536\u7528\u6237\u8f93\u5165\u7684\u591a\u4e2a\u503c\uff0c\u5e76\u901a\u8fc7\u5206\u5272\u5b57\u7b26\u4e32\u5c06\u5b83\u4eec\u5b58\u50a8\u5230\u5217\u8868\u4e2d\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>split()<\/code>\u65b9\u6cd5\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6309\u7a7a\u683c\u5206\u5f00\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">user_input = input(&quot;\u8bf7\u8f93\u5165\u591a\u4e2a\u503c\uff0c\u4ee5\u7a7a\u683c\u5206\u5f00\uff1a&quot;)\nvalues = user_input.split()\nprint(values)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u7528\u6237\u8f93\u5165\u7684\u591a\u4e2a\u503c\u5c31\u4f1a\u88ab\u5b58\u50a8\u4e3a\u5217\u8868\u5f62\u5f0f\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u63a5\u6536\u591a\u884c\u8f93\u5165\u7684\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5982\u679c\u5e0c\u671b\u7528\u6237\u8f93\u5165\u591a\u884c\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\uff0c\u76f4\u5230\u7528\u6237\u8f93\u5165\u7279\u5b9a\u7684\u7ed3\u675f\u6807\u5fd7\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">values = []\nwhile True:\n    line = input(&quot;\u8bf7\u8f93\u5165\u503c\uff08\u8f93\u5165&#39;\u7ed3\u675f&#39;\u4ee5\u9000\u51fa\uff09\uff1a&quot;)\n    if line == &#39;\u7ed3\u675f&#39;:\n        break\n    values.append(line)\nprint(values)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u7528\u6237\u9010\u884c\u8f93\u5165\u6570\u636e\uff0c\u76f4\u5230\u4ed6\u4eec\u51b3\u5b9a\u505c\u6b62\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5c06\u8f93\u5165\u7684\u591a\u4e2a\u503c\u8f6c\u6362\u4e3a\u7279\u5b9a\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u53ef\u4ee5\u5728\u63a5\u6536\u7528\u6237\u8f93\u5165\u540e\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6240\u9700\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5e0c\u671b\u5c06\u8f93\u5165\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u5217\u8868\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a  <\/p>\n<pre><code class=\"language-python\">user_input = input(&quot;\u8bf7\u8f93\u5165\u591a\u4e2a\u6570\u5b57\uff0c\u4ee5\u7a7a\u683c\u5206\u5f00\uff1a&quot;)\nnumbers = [int(x) for x in user_input.split()]\nprint(numbers)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u7075\u6d3b\u5730\u5904\u7406\u7528\u6237\u8f93\u5165\u5e76\u8f6c\u6362\u4e3a\u9002\u5408\u540e\u7eed\u5904\u7406\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u4f9d\u6b21\u8f93\u5165\u591a\u4e2a\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5982\u4f7f\u7528input\u51fd\u6570\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u5faa\u73af\u7b49\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9 [&hellip;]","protected":false},"author":3,"featured_media":1161470,"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\/1161466"}],"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=1161466"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161466\/revisions"}],"predecessor-version":[{"id":1161471,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161466\/revisions\/1161471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1161470"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1161466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1161466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1161466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}