{"id":1059882,"date":"2024-12-31T15:29:05","date_gmt":"2024-12-31T07:29:05","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1059882.html"},"modified":"2024-12-31T15:29:08","modified_gmt":"2024-12-31T07:29:08","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e8%bd%ac%e4%b8%8b%e4%b8%80%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1059882.html","title":{"rendered":"\u5982\u4f55\u7528python\u8f6c\u4e0b\u4e00\u884c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/4cc5d355-4f5a-41d3-8334-62238dfd7cd5.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u7528python\u8f6c\u4e0b\u4e00\u884c\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u8f6c\u4e0b\u4e00\u884c\u7684\u5e38\u89c1\u65b9\u6cd5\u6709\u51e0\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u6362\u884c\u5b57\u7b26\u3001\u4f7f\u7528\u591a\u884c\u5b57\u7b26\u4e32\u548c\u4f7f\u7528print\u51fd\u6570\u7684end\u53c2\u6570\u3002\u8fd9\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5206\u522b\u5e94\u5bf9\u4e0d\u540c\u7684\u573a\u666f\u9700\u6c42\u3002\u5728\u5e38\u89c1\u7684\u6587\u672c\u5904\u7406\u3001\u8f93\u51fa\u683c\u5f0f\u63a7\u5236\u7b49\u65b9\u9762\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u80fd\u53d1\u6325\u91cd\u8981\u4f5c\u7528\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c\u4f7f\u7528\u6362\u884c\u5b57\u7b26\u662f\u6700\u57fa\u7840\u4e14\u5e38\u7528\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u6362\u884c\u5b57\u7b26\uff08\\n\uff09\u5728\u5b57\u7b26\u4e32\u4e2d\u8868\u793a\u6362\u884c\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u9700\u8981\u6362\u884c\u7684\u5730\u65b9\u63d2\u5165\u8fd9\u4e00\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u5728print\u51fd\u6570\u4e2d\u4f7f\u7528\u6362\u884c\u5b57\u7b26\uff0c\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u591a\u884c\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u6362\u884c\u5b57\u7b26<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u4f7f\u7528\u6362\u884c\u5b57\u7b26\uff08\\n\uff09\u662f\u6700\u5e38\u89c1\u548c\u57fa\u7840\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u6362\u884c\u5b57\u7b26\u5728\u5b57\u7b26\u4e32\u4e2d\u8868\u793a\u6362\u884c\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u9700\u8981\u6362\u884c\u7684\u5730\u65b9\u63d2\u5165\u8fd9\u4e00\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello\\nWorld&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello<\/p>\n<p>World<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u76f4\u89c2\uff0c\u5f53\u4f60\u9700\u8981\u5728\u4e00\u6bb5\u6587\u672c\u4e2d\u63d2\u5165\u6362\u884c\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u6362\u884c\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u591a\u884c\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u591a\u884c\u5b57\u7b26\u4e32\u4f7f\u7528\u4e09\u4e2a\u5f15\u53f7\uff08&#39;&#39;&#39; \u6216 &quot;&quot;&quot;\uff09\u5305\u88f9\uff0c\u53ef\u4ee5\u5305\u542b\u591a\u884c\u5185\u5bb9\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5904\u7406\u6216\u8f93\u51fa\u5927\u6bb5\u6587\u672c\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">multi_line_string = &quot;&quot;&quot;Hello<\/p>\n<p>World&quot;&quot;&quot;<\/p>\n<p>print(multi_line_string)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello<\/p>\n<p>World<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u591a\u884c\u5b57\u7b26\u4e32\u4e0d\u4ec5\u53ef\u4ee5\u7528\u4e8e\u8f93\u51fa\u591a\u884c\u5185\u5bb9\uff0c\u8fd8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u65b9\u4fbf\u5730\u7ef4\u62a4\u548c\u7f16\u8f91\u591a\u884c\u6587\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528print\u51fd\u6570\u7684end\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u5728Python\u7684print\u51fd\u6570\u4e2d\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8f93\u51fa\u5185\u5bb9\u540e\u4f1a\u81ea\u52a8\u6dfb\u52a0\u4e00\u4e2a\u6362\u884c\u7b26\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539end\u53c2\u6570\u6765\u63a7\u5236\u8f93\u51fa\u7ed3\u675f\u65f6\u7684\u5b57\u7b26\uff0c\u4ece\u800c\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u8f93\u51fa\u63a7\u5236\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello&quot;, end=&quot;\\n&quot;)<\/p>\n<p>print(&quot;World&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello<\/p>\n<p>World<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7075\u6d3b\u63a7\u5236\u8f93\u51fa\u683c\u5f0f\uff0c\u4f8b\u5982\u5728\u6253\u5370\u591a\u4e2a\u53d8\u91cf\u65f6\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5206\u9694\u7b26\u548c\u7ed3\u675f\u7b26\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b57\u7b26\u4e32\u62fc\u63a5\u4e0e\u683c\u5f0f\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u4e00\u4e9b\u590d\u6742\u7684\u6587\u672c\u751f\u6210\u573a\u666f\u4e2d\uff0c\u5b57\u7b26\u4e32\u62fc\u63a5\u4e0e\u683c\u5f0f\u5316\u4e5f\u80fd\u6709\u6548\u5e2e\u52a9\u6211\u4eec\u5b9e\u73b0\u8f6c\u4e0b\u4e00\u884c\u7684\u9700\u6c42\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5b57\u7b26\u4e32\u7684join\u65b9\u6cd5\u6216\u8005\u4f7f\u7528\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u5de5\u5177\u6765\u751f\u6210\u9700\u8981\u7684\u591a\u884c\u6587\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">lines = [&quot;Hello&quot;, &quot;World&quot;]<\/p>\n<p>formatted_string = &quot;\\n&quot;.join(lines)<\/p>\n<p>print(formatted_string)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello<\/p>\n<p>World<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u9002\u5408\u9700\u8981\u52a8\u6001\u751f\u6210\u591a\u884c\u6587\u672c\u7684\u60c5\u51b5\uff0c\u901a\u8fc7join\u65b9\u6cd5\u53ef\u4ee5\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u6309\u7167\u6307\u5b9a\u7684\u5206\u9694\u7b26\u62fc\u63a5\u5728\u4e00\u8d77\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u6587\u4ef6\u64cd\u4f5c\u4e2d\u7684\u6362\u884c<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6587\u4ef6\u8bfb\u5199\u65f6\uff0c\u6362\u884c\u4e5f\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u6982\u5ff5\u3002\u5728\u5199\u5165\u6587\u4ef6\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6362\u884c\u5b57\u7b26\u6765\u7ec4\u7ec7\u6587\u672c\u5185\u5bb9\u3002\u5728\u8bfb\u53d6\u6587\u4ef6\u65f6\uff0c\u53ef\u4ee5\u9010\u884c\u8bfb\u53d6\u6765\u5904\u7406\u6587\u4ef6\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&quot;example.txt&quot;, &quot;w&quot;) as file:<\/p>\n<p>    file.write(&quot;Hello\\nWorld&quot;)<\/p>\n<p>with open(&quot;example.txt&quot;, &quot;r&quot;) as file:<\/p>\n<p>    for line in file:<\/p>\n<p>        print(line, end=&quot;&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello<\/p>\n<p>World<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u6587\u4ef6\u64cd\u4f5c\u4e2d\u7684\u6362\u884c\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u548c\u7ec4\u7ec7\u6587\u4ef6\u4e2d\u7684\u6587\u672c\u5185\u5bb9\uff0c\u786e\u4fdd\u6587\u672c\u683c\u5f0f\u7b26\u5408\u9884\u671f\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5904\u7406\u6362\u884c\u7b26<\/h3>\n<\/p>\n<p><p>\u5728\u4e00\u4e9b\u9ad8\u7ea7\u6587\u672c\u5904\u7406\u573a\u666f\u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u7075\u6d3b\u5730\u5904\u7406\u6362\u884c\u7b26\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u67e5\u627e\u548c\u66ff\u6362\u6587\u672c\u4e2d\u7684\u6362\u884c\u7b26\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>text = &quot;Hello\\nWorld&quot;<\/p>\n<p>new_text = re.sub(r&#39;\\n&#39;, &#39; &#39;, text)<\/p>\n<p>print(new_text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello World<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u7cbe\u786e\u5730\u63a7\u5236\u6587\u672c\u4e2d\u7684\u6362\u884c\u7b26\uff0c\u8fdb\u884c\u590d\u6742\u7684\u6587\u672c\u5904\u7406\u548c\u683c\u5f0f\u5316\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5904\u7406CSV\u6587\u4ef6\u4e2d\u7684\u6362\u884c<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406CSV\u6587\u4ef6\u65f6\uff0c\u6362\u884c\u7b26\u7684\u5904\u7406\u4e5f\u5c24\u4e3a\u91cd\u8981\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684csv\u6a21\u5757\u6765\u8bfb\u53d6\u548c\u5199\u5165CSV\u6587\u4ef6\uff0c\u786e\u4fdd\u6587\u4ef6\u4e2d\u7684\u6362\u884c\u7b26\u5904\u7406\u6b63\u786e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import csv<\/p>\n<p>data = [[&quot;Name&quot;, &quot;Age&quot;], [&quot;Alice&quot;, 30], [&quot;Bob&quot;, 25]]<\/p>\n<p>with open(&quot;example.csv&quot;, &quot;w&quot;, newline=&#39;&#39;) as file:<\/p>\n<p>    writer = csv.writer(file)<\/p>\n<p>    writer.writerows(data)<\/p>\n<p>with open(&quot;example.csv&quot;, &quot;r&quot;) as file:<\/p>\n<p>    reader = csv.reader(file)<\/p>\n<p>    for row in reader:<\/p>\n<p>        print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>[&#39;Name&#39;, &#39;Age&#39;]<\/p>\n<p>[&#39;Alice&#39;, &#39;30&#39;]<\/p>\n<p>[&#39;Bob&#39;, &#39;25&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7csv\u6a21\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406CSV\u6587\u4ef6\u4e2d\u7684\u6362\u884c\u7b26\uff0c\u786e\u4fdd\u6570\u636e\u7684\u6b63\u786e\u8bfb\u5199\u548c\u683c\u5f0f\u5316\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u6a21\u677f<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u7684\u5b57\u7b26\u4e32\u6a21\u677f\uff08string.Template\uff09\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u751f\u6210\u9700\u8981\u7684\u591a\u884c\u6587\u672c\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u66ff\u6362\u5360\u4f4d\u7b26\u6765\u52a8\u6001\u751f\u6210\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from string import Template<\/p>\n<p>template = Template(&quot;Hello\\n$who&quot;)<\/p>\n<p>output = template.substitute(who=&quot;World&quot;)<\/p>\n<p>print(output)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello<\/p>\n<p>World<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b57\u7b26\u4e32\u6a21\u677f\u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u751f\u6210\u591a\u884c\u6587\u672c\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u66ff\u6362\u5360\u4f4d\u7b26\u6765\u52a8\u6001\u751f\u6210\u5185\u5bb9\uff0c\u9002\u7528\u4e8e\u9700\u8981\u52a8\u6001\u751f\u6210\u591a\u884c\u6587\u672c\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u6587\u672c\u5904\u7406\u4e2d\u7684\u6362\u884c\u7b26<\/h3>\n<\/p>\n<p><p>\u5728\u4e00\u4e9b\u6587\u672c\u5904\u7406\u4efb\u52a1\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5bf9\u6587\u672c\u4e2d\u7684\u6362\u884c\u7b26\u8fdb\u884c\u7279\u6b8a\u5904\u7406\u3002\u4f8b\u5982\uff0c\u5728\u5904\u7406\u65e5\u5fd7\u6587\u4ef6\u6216\u89e3\u6790\u6587\u672c\u6570\u636e\u65f6\uff0c\u6362\u884c\u7b26\u7684\u5904\u7406\u53ef\u80fd\u4f1a\u5f71\u54cd\u5230\u6700\u7ec8\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">text = &quot;Hello\\nWorld\\nWelcome to Python&quot;<\/p>\n<p>lines = text.splitlines()<\/p>\n<p>for line in lines:<\/p>\n<p>    print(line)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u4f1a\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello<\/p>\n<p>World<\/p>\n<p>Welcome to Python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7splitlines\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6587\u672c\u6309\u7167\u6362\u884c\u7b26\u5206\u5272\u6210\u591a\u884c\uff0c\u65b9\u4fbf\u540e\u7eed\u7684\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8f6c\u4e0b\u4e00\u884c\uff0c\u5305\u62ec\u4f7f\u7528\u6362\u884c\u5b57\u7b26\u3001\u591a\u884c\u5b57\u7b26\u4e32\u3001print\u51fd\u6570\u7684end\u53c2\u6570\u3001\u5b57\u7b26\u4e32\u62fc\u63a5\u4e0e\u683c\u5f0f\u5316\u3001\u6587\u4ef6\u64cd\u4f5c\u4e2d\u7684\u6362\u884c\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u5904\u7406\u6362\u884c\u7b26\u3001\u5904\u7406CSV\u6587\u4ef6\u4e2d\u7684\u6362\u884c\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u6a21\u677f\u4ee5\u53ca\u6587\u672c\u5904\u7406\u4e2d\u7684\u6362\u884c\u7b26\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u52a3\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\u548c\u9700\u6c42\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u6587\u672c\u7684\u6362\u884c\u548c\u683c\u5f0f\u63a7\u5236\u3002\u901a\u8fc7\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u6709\u6548\u5730\u5904\u7406\u548c\u7ec4\u7ec7\u6587\u672c\u5185\u5bb9\uff0c\u786e\u4fdd\u6587\u672c\u683c\u5f0f\u7b26\u5408\u9884\u671f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u63d2\u5165\u6362\u884c\u7b26\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6362\u884c\u7b26\u201c\\n\u201d\u6765\u63d2\u5165\u6362\u884c\u3002\u5c06\u5176\u653e\u7f6e\u5728\u5b57\u7b26\u4e32\u4e2d\uff0c\u7a0b\u5e8f\u5728\u8f93\u51fa\u65f6\u4f1a\u81ea\u52a8\u6362\u884c\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">print(&quot;Hello World!\\nWelcome to Python.&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u5728\u201cHello World!\u201d\u548c\u201cWelcome to Python.\u201d\u4e4b\u95f4\u63d2\u5165\u4e00\u4e2a\u6362\u884c\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u8bfb\u53d6\u591a\u884c\u8f93\u5165\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u7ed3\u5408\u5faa\u73af\u6765\u8bfb\u53d6\u591a\u884c\u8f93\u5165\u3002\u5f53\u7528\u6237\u8f93\u5165\u7a7a\u884c\u65f6\uff0c\u53ef\u4ee5\u505c\u6b62\u8bfb\u53d6\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">lines = []\nwhile True:\n    line = input(&quot;\u8bf7\u8f93\u5165\u4e00\u884c\u6587\u672c\uff08\u8f93\u5165\u7a7a\u884c\u7ed3\u675f\uff09\uff1a&quot;)\n    if line == &quot;&quot;:\n        break\n    lines.append(line)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u6536\u96c6\u7528\u6237\u8f93\u5165\u7684\u591a\u884c\u6587\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u591a\u884c\u5b57\u7b26\u4e32\uff1f<\/strong><br \/>\u4f7f\u7528\u4e09\u91cd\u5f15\u53f7\uff08&quot;&quot;&quot;\u6216&#39;&#39;&#39;\uff09\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u591a\u884c\u5b57\u7b26\u4e32\u3002\u8fd9\u79cd\u65b9\u5f0f\u4fdd\u7559\u4e86\u6362\u884c\u548c\u7a7a\u683c\uff0c\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">text = &quot;&quot;&quot;\u8fd9\u662f\u7b2c\u4e00\u884c\n\u8fd9\u662f\u7b2c\u4e8c\u884c\n\u8fd9\u662f\u7b2c\u4e09\u884c&quot;&quot;&quot;\nprint(text)\n<\/code><\/pre>\n<p>\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u5b9a\u4e49\u7684\u5b57\u7b26\u4e32\u4f1a\u4fdd\u7559\u6240\u6709\u6362\u884c\u7b26\u548c\u683c\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u8f6c\u4e0b\u4e00\u884c\u7684\u5e38\u89c1\u65b9\u6cd5\u6709\u51e0\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u6362\u884c\u5b57\u7b26\u3001\u4f7f\u7528\u591a\u884c\u5b57\u7b26\u4e32\u548c\u4f7f\u7528print\u51fd\u6570\u7684end\u53c2\u6570\u3002\u8fd9 [&hellip;]","protected":false},"author":3,"featured_media":1059886,"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\/1059882"}],"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=1059882"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1059882\/revisions"}],"predecessor-version":[{"id":1059889,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1059882\/revisions\/1059889"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1059886"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1059882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1059882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1059882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}