{"id":275683,"date":"2024-05-16T14:33:30","date_gmt":"2024-05-16T06:33:30","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/275683.html"},"modified":"2024-05-16T14:33:40","modified_gmt":"2024-05-16T06:33:40","slug":"python-%e9%a1%b9%e7%9b%ae%e6%80%8e%e4%b9%88%e8%be%93%e5%87%ba-hello-world-%e4%bb%a3%e7%a0%81-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/275683.html","title":{"rendered":"python \u9879\u76ee\u600e\u4e48\u8f93\u51fa hello world \u4ee3\u7801"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24200428\/e815abab-3583-4e5a-9f0b-a3d3599f170a.webp\" alt=\"python \u9879\u76ee\u600e\u4e48\u8f93\u51fa hello world \u4ee3\u7801\" \/><\/p>\n<p><p>\u5728Python\u9879\u76ee\u4e2d\u8f93\u51fa\u201cHello World\u201d\u4ee3\u7801\u662f\u7f16\u7a0b\u521d\u5b66\u8005\u8fc8\u51fa\u7684\u7b2c\u4e00\u6b65\uff0c\u5b83\u4f53\u73b0\u4e86\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u7840\u8bed\u6cd5\u7ed3\u6784\u548c\u8fd0\u884c\u673a\u5236\u3002<strong>\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u6211\u4eec\u4e3b\u8981\u505a\u4e09\u4ef6\u4e8b\uff1a\u5b89\u88c5Python\u73af\u5883\u3001\u7f16\u5199Hello World\u4ee3\u7801\u3001\u8fd0\u884c\u4ee3\u7801\u3002<\/strong> \u5176\u4e2d\u5b89\u88c5Python\u73af\u5883\u662f\u7f16\u5199\u548c\u6267\u884cPython\u4ee3\u7801\u7684\u524d\u63d0\uff0c\u5b83\u5305\u62ec\u4e0b\u8f7dPython\u89e3\u91ca\u5668\u548c\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u786e\u4fddPython\u547d\u4ee4\u5728\u4efb\u4f55\u76ee\u5f55\u4e0b\u90fd\u80fd\u88ab\u6b63\u786e\u8bc6\u522b\u548c\u6267\u884c\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u5b89\u88c5PYTHON\u73af\u5883<\/h2>\n<\/p>\n<p><p>\u5b89\u88c5Python\u73af\u5883\u901a\u5e38\u662f\u4efb\u4f55Python\u9879\u76ee\u7684\u524d\u63d0\u6b65\u9aa4\u3002\u5bf9\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u8fd9\u4e00\u8fc7\u7a0b\u5305\u62ec\u4e0b\u8f7dPython\u89e3\u91ca\u5668\u5e76\u786e\u4fdd\u5176\u80fd\u591f\u5728\u547d\u4ee4\u884c\u4e2d\u5168\u5c40\u8bbf\u95ee\u3002\u5bf9\u4e8e\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5b89\u88c5\u6b65\u9aa4\u7565\u6709\u4e0d\u540c\uff0c\u4f46\u603b\u4f53\u4e0a\u9075\u5faa\u4e0b\u8f7d\u3001\u5b89\u88c5\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u7684\u6807\u51c6\u6d41\u7a0b\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u524d\u5f80Python\u5b98\u7f51\u4e0b\u8f7d\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u5bf9\u5e94\u7248\u672c\u7684Python\u5b89\u88c5\u5305\u3002\u5b98\u7f51\u63d0\u4f9b\u4e86Windows\u3001macOS\u548cLinux\u7b49\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u3002\u5728\u4e0b\u8f7d\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u9009\u62e9\u4e86\u4e0e\u7cfb\u7edf\u67b6\u6784\uff0832\u4f4d\u621664\u4f4d\uff09\u5339\u914d\u7684\u7248\u672c\u3002\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u542f\u52a8\u5b89\u88c5\u7a0b\u5e8f\u5e76\u9075\u5faa\u5411\u5bfc\u5b8c\u6210\u5b89\u88c5\u3002\u5bf9\u4e8eWindows\u7528\u6237\uff0c\u5b89\u88c5\u65f6\u8bf7\u786e\u4fdd\u52fe\u9009\u4e86\u201cAdd Python X.X to PATH\u201d\uff0c\u4ece\u800c\u5c06Python\u52a0\u5165\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u4f7f\u5f97\u5728\u4efb\u610f\u76ee\u5f55\u4e0b\u90fd\u80fd\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\u9a8c\u8bc1Python\u662f\u5426\u6210\u529f\u5b89\u88c5\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u5982\u679c\u7cfb\u7edf\u8fd4\u56de\u4e86Python\u7684\u7248\u672c\u53f7\uff0c\u90a3\u4e48\u606d\u559c\u4f60\uff0cPython\u73af\u5883\u5df2\u7ecf\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u7f16\u5199HELLO WORLD\u4ee3\u7801<\/h2>\n<\/p>\n<p><p>\u7f16\u5199\u201cHello World\u201d\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\uff0c\u5b83\u4e0d\u9700\u8981\u590d\u6742\u7684\u7f16\u7a0b\u7ed3\u6784\uff0c\u53ea\u9700\u8981\u51e0\u884c\u4ee3\u7801\u3002\u6253\u5f00\u6587\u672c\u7f16\u8f91\u5668\uff0c\u5982Notepad\u3001VS Code\u6216PyCharm\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5e76\u4fdd\u5b58\u4e3a<code>hello.py<\/code>\u3002<\/p>\n<\/p>\n<p><p>\u5728<code>hello.py<\/code>\u6587\u4ef6\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello World&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u884c\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u8c03\u7528Python\u5185\u7f6e\u7684<code>print<\/code>\u51fd\u6570\uff0c\u5c06\u62ec\u53f7\u5185\u7684\u5b57\u7b26\u4e32\u5185\u5bb9\u8f93\u51fa\u5230\u7ec8\u7aef\u3002\u8fd9\u91cc\u7684\u5b57\u7b26\u4e32\u5c31\u662f\u6211\u4eec\u719f\u77e5\u7684&quot;Hello World&quot;\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u8fd0\u884c\u4ee3\u7801<\/h2>\n<\/p>\n<p><p>\u6709\u4e86Python\u73af\u5883\u548c<code>hello.py<\/code>\u6587\u4ef6\uff0c\u63a5\u4e0b\u6765\u53ea\u9700\u8fd0\u884c\u8fd9\u4e2a\u6587\u4ef6\u3002\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u901a\u8fc7<code>cd<\/code>\u547d\u4ee4\u5207\u6362\u5230\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c<code>hello.py<\/code>\u4f4d\u4e8e<code>C:\\Users\\YourName\\Documents\\PythonProjects<\/code>\u76ee\u5f55\u4e0b\uff0c\u5c31\u9700\u8981\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">cd C:\\Users\\YourName\\Documents\\PythonProjects<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fdb\u5165\u76ee\u5f55\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c<code>hello.py<\/code>\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-shell\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4e00\u5207\u987a\u5229\uff0c\u5c4f\u5e55\u4e0a\u5c06\u663e\u793a\u201cHello World\u201d\u3002\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u8fd0\u884c\u4e86Python\u9879\u76ee\u4e2d\u7684\u7b2c\u4e00\u4e2a\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u7406\u89e3PYTHON\u7684\u57fa\u7840<\/h2>\n<\/p>\n<p><p>\u8f93\u51fa\u201cHello World\u201d\u867d\u7136\u7b80\u5355\uff0c\u4f46\u5176\u80cc\u540e\u8574\u542b\u4e86Python\u8bed\u8a00\u7684\u4e00\u4e9b\u57fa\u7840\u6982\u5ff5\u3002\u7406\u89e3\u8fd9\u4e9b\u57fa\u7840\u6982\u5ff5\u5bf9\u4e8e\u6df1\u5165\u5b66\u4e60Python\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><p><strong>Python\u662f\u4e00\u79cd\u89e3\u91ca\u578b\u8bed\u8a00<\/strong>\uff0c\u76f8\u8f83\u4e8e\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u5b83\u7684\u4ee3\u7801\u5728\u8fd0\u884c\u65f6\u624d\u7531\u89e3\u91ca\u5668\u9010\u53e5\u7ffb\u8bd1\u6210\u673a\u5668\u7801\uff0c\u8fd9\u4e5f\u610f\u5473\u7740Python\u4ee3\u7801\u5177\u6709\u826f\u597d\u7684\u8de8\u5e73\u53f0\u6027\u3002<strong>\u89e3\u91ca\u578b\u8bed\u8a00\u7684\u8fd9\u4e00\u7279\u6027\u8ba9Python\u5728\u6570\u636e\u79d1\u5b66\u3001\u7f51\u7ad9\u5f00\u53d1\u548c\u81ea\u52a8\u5316\u811a\u672c\u7b49\u9886\u57df\u975e\u5e38\u53d7\u6b22\u8fce\u3002<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684\u8bbe\u8ba1\u54f2\u5b66\u5f3a\u8c03\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u5176\u76ee\u6807\u662f\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u7528\u66f4\u5c11\u7684\u4ee3\u7801\u505a\u66f4\u591a\u7684\u4e8b\u60c5\u3002\u6b63\u56e0\u4e3a\u5982\u6b64\uff0cPython\u6210\u4e3a\u4e86\u4e0d\u5c11\u7f16\u7a0b\u65b0\u624b\u7684\u9996\u9009\u8bed\u8a00\uff0c\u540c\u65f6\u4e5f\u88ab\u5e94\u7528\u4e8e\u4f17\u591a\u7684\u5f00\u53d1\u9886\u57df\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u62d3\u5c55\u5b66\u4e60<\/h2>\n<\/p>\n<p><p>\u638c\u63e1\u8f93\u51fa\u201cHello World\u201d\u540e\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63a2\u7d22Python\u7684\u5176\u4ed6\u529f\u80fd\uff0c\u6bd4\u5982\u53d8\u91cf\u3001\u6570\u636e\u7c7b\u578b\u3001\u63a7\u5236\u6d41\u3001\u51fd\u6570\u7b49\u57fa\u7840\u6982\u5ff5\u3002\u901a\u8fc7\u8fd9\u4e9b\u5185\u5bb9\u7684\u5b66\u4e60\uff0c\u53ef\u4ee5\u9010\u6e10\u6784\u5efa\u8d77\u5bf9Python\u66f4\u52a0\u6df1\u5165\u3001\u5168\u9762\u7684\u8ba4\u8bc6\u3002<\/p>\n<\/p>\n<p><p>\u6b64\u5916\uff0c\u5b9e\u9645\u9879\u76ee\u5f00\u53d1\u4e2d\u5e38\u5e38\u6d89\u53ca\u5230\u6a21\u5757\u548c\u5305\u7684\u4f7f\u7528\uff0c\u7406\u89e3\u5b83\u4eec\u5982\u4f55\u5de5\u4f5c\u4ee5\u53ca\u5982\u4f55\u5408\u7406\u5229\u7528Python\u793e\u533a\u63d0\u4f9b\u7684\u4e30\u5bcc\u6a21\u5757\u8d44\u6e90\uff0c\u5c06\u662f\u4f60\u7f16\u7a0b\u65c5\u7a0b\u4e2d\u7684\u53c8\u4e00\u91cd\u8981\u91cc\u7a0b\u7891\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u53c2\u52a0\u9879\u76ee\u3001\u7f16\u5199\u5c0f\u7a0b\u5e8f\u548c\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\uff0c\u4f60\u5c06\u4e0d\u65ad\u63d0\u5347\u81ea\u5df1\u7684Python\u7f16\u7a0b\u6280\u80fd\u3002\u8bb0\u4f4f\uff0c\u7f16\u7a0b\u662f\u4e00\u4e2a\u5b9e\u8df5\u7684\u8fc7\u7a0b\uff0c\u53ea\u6709\u901a\u8fc7\u4e0d\u65ad\u7684\u7f16\u5199\u4ee3\u7801\u548c\u89e3\u51b3\u95ee\u9898\uff0c\u624d\u80fd\u771f\u6b63\u638c\u63e1\u7f16\u7a0b\u7684\u827a\u672f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q: \u5728 Python \u9879\u76ee\u4e2d\u5982\u4f55\u7f16\u5199\u4e00\u4e2a hello world \u7a0b\u5e8f\uff1f<\/strong><\/p>\n<p>A: \u7f16\u5199\u4e00\u4e2a hello world \u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u5728 Python \u9879\u76ee\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Python \u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u4f7f\u7528 <code>print<\/code> \u8bed\u53e5\u8f93\u51fa &quot;hello world&quot;\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">print(&quot;hello world&quot;)\n<\/code><\/pre>\n<p><strong>Q: Python \u9879\u76ee\u8fd0\u884c\u65f6\uff0c\u5982\u4f55\u5728\u63a7\u5236\u53f0\u8f93\u51fa hello world \u7684\u7ed3\u679c\uff1f<\/strong><\/p>\n<p>A: \u5728 Python \u9879\u76ee\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c Python \u811a\u672c\u6765\u67e5\u770b hello world \u7684\u8f93\u51fa\u7ed3\u679c\u3002\u9996\u5148\uff0c\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u754c\u9762\uff0c\u7136\u540e\u8fdb\u5165\u5230\u4f60\u7684\u9879\u76ee\u6240\u5728\u7684\u76ee\u5f55\u3002\u63a5\u4e0b\u6765\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>python \u6587\u4ef6\u540d.py\n<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>\u6587\u4ef6\u540d.py<\/code> \u662f\u4f60\u4fdd\u5b58 hello world \u4ee3\u7801\u7684\u6587\u4ef6\u540d\u3002\u8fd0\u884c\u8be5\u547d\u4ee4\u540e\uff0c\u4f60\u5c06\u5728\u63a7\u5236\u53f0\u4e2d\u770b\u5230\u8f93\u51fa\u7ed3\u679c &quot;hello world&quot;\u3002<\/p>\n<p><strong>Q: \u5982\u4f55\u5728 Python \u9879\u76ee\u4e2d\u5c06 hello world \u7684\u7ed3\u679c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff1f<\/strong><\/p>\n<p>A: \u5982\u679c\u4f60\u60f3\u5c06 hello world \u7684\u7ed3\u679c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u501f\u52a9 Python \u7684\u6587\u4ef6\u64cd\u4f5c\u529f\u80fd\u3002\u9996\u5148\uff0c\u5728\u4f60\u7684 Python \u9879\u76ee\u4e2d\u5f15\u5165\u6587\u4ef6\u64cd\u4f5c\u7684\u6838\u5fc3\u6a21\u5757 <code>io<\/code>\u3002\u7136\u540e\uff0c\u4f7f\u7528 <code>open<\/code> \u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u5e76\u6307\u5b9a\u6587\u4ef6\u540d\u548c\u6253\u5f00\u6a21\u5f0f\uff08\u4f8b\u5982 <code>w<\/code> \u8868\u793a\u5199\u5165\u6a21\u5f0f\uff09\u3002<br \/>\n\u63a5\u7740\uff0c\u4f7f\u7528 <code>write<\/code> \u65b9\u6cd5\u5c06\u8981\u4fdd\u5b58\u7684\u7ed3\u679c\u5199\u5165\u6587\u4ef6\u4e2d\u3002\u6700\u540e\uff0c\u5173\u95ed\u6587\u4ef6\u4ee5\u786e\u4fdd\u6587\u4ef6\u7684\u5199\u5165\u64cd\u4f5c\u5b8c\u6210\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">file = open(&quot;output.txt&quot;, &quot;w&quot;)\nfile.write(&quot;hello world&quot;)\nfile.close()\n<\/code><\/pre>\n<p>\u5728\u6267\u884c\u5b8c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u4f60\u5c06\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>output.txt<\/code> \u7684\u6587\u4ef6\uff0c\u5e76\u5c06 &quot;hello world&quot; \u5199\u5165\u5176\u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u9879\u76ee\u4e2d\u8f93\u51fa\u201cHello World\u201d\u4ee3\u7801\u662f\u7f16\u7a0b\u521d\u5b66\u8005\u8fc8\u51fa\u7684\u7b2c\u4e00\u6b65\uff0c\u5b83\u4f53\u73b0\u4e86\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u7840\u8bed\u6cd5\u7ed3\u6784 [&hellip;]","protected":false},"author":3,"featured_media":275694,"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\/275683"}],"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=275683"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/275683\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/275694"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=275683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=275683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=275683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}