{"id":1066332,"date":"2024-12-31T16:25:24","date_gmt":"2024-12-31T08:25:24","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1066332.html"},"modified":"2024-12-31T16:25:27","modified_gmt":"2024-12-31T08:25:27","slug":"python%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c%e4%b8%80%e4%b8%aapy%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1066332.html","title":{"rendered":"python\u5982\u4f55\u8fd0\u884c\u4e00\u4e2apy\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/ac9c47a1-41c0-424a-9753-a0ce3875d85b.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u8fd0\u884c\u4e00\u4e2apy\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>\u8fd0\u884c\u4e00\u4e2aPython\u6587\u4ef6\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001IDLE\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u7b49\u3002\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884c\u3001\u4f7f\u7528Python IDLE\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u8fd0\u884c\u3002<\/strong> \u8fd9\u91cc\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884c\u4e00\u4e2aPython\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165 <code>python --version<\/code> \u6216 <code>python3 --version<\/code> \u6765\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u4e86Python\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5Python\uff0c\u8bf7\u5148\u4ecePython\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u6587\u4ef6<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6309\u4e0b <code>Win + R<\/code>\uff0c\u8f93\u5165 <code>cmd<\/code> \u5e76\u6309\u4e0b\u56de\u8f66\u6765\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u5728Mac\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230Python\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528 <code>cd<\/code> \u547d\u4ee4\u5bfc\u822a\u5230\u5b58\u653ePython\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684Python\u6587\u4ef6\u4f4d\u4e8e <code>C:\\Users\\YourUsername\\Documents\\Python<\/code> \u76ee\u5f55\u4e0b\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd C:\\Users\\YourUsername\\Documents\\Python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u4f60\u5728Python\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884cPython\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python filename.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528 <code>python3<\/code> \u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 filename.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u66ff\u6362 <code>filename.py<\/code> \u4e3a\u4f60\u5b9e\u9645\u7684Python\u6587\u4ef6\u540d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u901a\u8fc7Python IDLE\u8fd0\u884c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00Python IDLE<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u83dc\u5355\uff08Windows\uff09\u6216\u5e94\u7528\u7a0b\u5e8f\uff08Mac\uff09\u4e2d\u627e\u5230\u5e76\u6253\u5f00Python IDLE\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6253\u5f00\u4f60\u7684Python\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python IDLE\u4e2d\uff0c\u70b9\u51fb <code>File -&gt; Open<\/code>\uff0c\u7136\u540e\u9009\u62e9\u4f60\u7684Python\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python IDLE\u4e2d\u6253\u5f00\u6587\u4ef6\u540e\uff0c\u70b9\u51fb <code>Run -&gt; Run Module<\/code> \u6216\u6309\u4e0b <code>F5<\/code> \u952e\u6765\u8fd0\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u901a\u8fc7\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u8fd0\u884c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u5e76\u6253\u5f00IDE<\/strong><\/p>\n<\/p>\n<p><p>\u5e38\u89c1\u7684Python IDE\u5305\u62ecPyCharm\u3001VSCode\u3001Spyder\u7b49\u3002\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4f60\u559c\u6b22\u7684IDE\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u6216\u521b\u5efaPython\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728IDE\u4e2d\u5bfc\u5165\u6216\u521b\u5efa\u4f60\u7684Python\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728IDE\u4e2d\u901a\u5e38\u4f1a\u6709\u4e00\u4e2a\u8fd0\u884c\u6309\u94ae\u6216\u8005\u83dc\u5355\u9009\u9879\u6765\u8fd0\u884cPython\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u4f60\u53ef\u4ee5\u53f3\u952e\u70b9\u51fbPython\u6587\u4ef6\u5e76\u9009\u62e9 <code>Run &#39;filename&#39;<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u8be6\u7ec6\u63cf\u8ff0\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u6587\u4ef6\u662f\u975e\u5e38\u65b9\u4fbf\u548c\u9ad8\u6548\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5Python\u662f\u5426\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u547d\u4ee4\u884c\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5Python\u662f\u5426\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679cPython\u5df2\u5b89\u88c5\uff0c\u4f60\u5c06\u770b\u5230\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u7684\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Python 3.9.7<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230Python\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528 <code>cd<\/code> \u547d\u4ee4\u5bfc\u822a\u5230\u5b58\u653ePython\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684Python\u6587\u4ef6\u4f4d\u4e8e <code>C:\\Users\\YourUsername\\Documents\\Python<\/code> \u76ee\u5f55\u4e0b\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd C:\\Users\\YourUsername\\Documents\\Python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u4f60\u5728Python\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884cPython\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python filename.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528 <code>python3<\/code> \u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 filename.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684Python\u6587\u4ef6\u5305\u542b\u5982\u4e0b\u5185\u5bb9\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>\u8fd0\u884c\u540e\uff0c\u4f60\u5c06\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e00\u3001\u5b89\u88c5Python<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7dPython\u5b89\u88c5\u7a0b\u5e8f<\/strong><\/p>\n<\/p>\n<p><p>\u8bbf\u95eePython\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%E5%B9%B6%E4%B8%8B%E8%BD%BD%E9%80%82%E7%94%A8%E4%BA%8E%E4%BD%A0%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84Python%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F%E3%80%82\">https:\/\/www.python.org\/\uff09\u5e76\u4e0b\u8f7d\u9002\u7528\u4e8e\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u5b89\u88c5\u7a0b\u5e8f\u3002<\/a><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong><\/p>\n<\/p>\n<p><p>\u8fd0\u884c\u4e0b\u8f7d\u7684\u5b89\u88c5\u7a0b\u5e8f\uff0c\u5e76\u786e\u4fdd\u9009\u4e2d\u201cAdd Python to PATH\u201d\u9009\u9879\u3002\u8fd9\u5c06\u4f7f\u4f60\u80fd\u591f\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528 <code>python<\/code> \u547d\u4ee4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u6253\u5f00\u547d\u4ee4\u884c\uff0c\u8f93\u5165 <code>python --version<\/code> \u6216 <code>python3 --version<\/code> \u6765\u9a8c\u8bc1Python\u662f\u5426\u6b63\u786e\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u7f16\u5199Python\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efaPython\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982Notepad\u3001Sublime Text\u3001VSCode\u7b49\uff09\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a <code>.py<\/code> \u6269\u5c55\u540d\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>hello.py<\/code> \u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199\u4ee3\u7801<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u4e2d\u7f16\u5199\u4f60\u7684Python\u4ee3\u7801\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6309\u4e0b <code>Win + R<\/code>\uff0c\u8f93\u5165 <code>cmd<\/code> \u5e76\u6309\u4e0b\u56de\u8f66\u6765\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u5728Mac\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528 <code>cd<\/code> \u547d\u4ee4\u5bfc\u822a\u5230\u5b58\u653ePython\u811a\u672c\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684Python\u811a\u672c\u4f4d\u4e8e <code>C:\\Users\\YourUsername\\Documents\\Python<\/code> \u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd C:\\Users\\YourUsername\\Documents\\Python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u4f60\u5728\u811a\u672c\u6240\u5728\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884cPython\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u5728\u67d0\u4e9b\u7cfb\u7edf\u4e2d\u4f7f\u7528 <code>python3<\/code> \u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u540e\uff0c\u4f60\u5c06\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">Hello, World!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u901a\u8fc7IDLE\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6253\u5f00Python IDLE<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u83dc\u5355\uff08Windows\uff09\u6216\u5e94\u7528\u7a0b\u5e8f\uff08Mac\uff09\u4e2d\u627e\u5230\u5e76\u6253\u5f00Python IDLE\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6253\u5f00\u4f60\u7684Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python IDLE\u4e2d\uff0c\u70b9\u51fb <code>File -&gt; Open<\/code>\uff0c\u7136\u540e\u9009\u62e9\u4f60\u7684Python\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python IDLE\u4e2d\u6253\u5f00\u811a\u672c\u540e\uff0c\u70b9\u51fb <code>Run -&gt; Run Module<\/code> \u6216\u6309\u4e0b <code>F5<\/code> \u952e\u6765\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u901a\u8fc7IDE\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u5e76\u6253\u5f00IDE<\/strong><\/p>\n<\/p>\n<p><p>\u5e38\u89c1\u7684Python IDE\u5305\u62ecPyCharm\u3001VSCode\u3001Spyder\u7b49\u3002\u4e0b\u8f7d\u5e76\u5b89\u88c5\u4f60\u559c\u6b22\u7684IDE\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u6216\u521b\u5efaPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728IDE\u4e2d\u5bfc\u5165\u6216\u521b\u5efa\u4f60\u7684Python\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728IDE\u4e2d\u901a\u5e38\u4f1a\u6709\u4e00\u4e2a\u8fd0\u884c\u6309\u94ae\u6216\u8005\u83dc\u5355\u9009\u9879\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u53ef\u4ee5\u53f3\u952e\u70b9\u51fbPython\u811a\u672c\u5e76\u9009\u62e9 <code>Run &#39;hello.py&#39;<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u8c03\u8bd5Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u8c03\u8bd5\u662f\u7f16\u7a0b\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u90e8\u5206\u3002\u901a\u8fc7\u8c03\u8bd5\uff0c\u4f60\u53ef\u4ee5\u4e00\u6b65\u6b65\u6267\u884c\u4ee3\u7801\uff0c\u68c0\u67e5\u53d8\u91cf\u7684\u503c\uff0c\u627e\u51fa\u5e76\u4fee\u590d\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528Python\u7684\u5185\u7f6e\u8c03\u8bd5\u5668\uff08pdb\uff09\u8fdb\u884c\u8c03\u8bd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u65ad\u70b9<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4f60\u60f3\u8981\u68c0\u67e5\u7684\u5730\u65b9\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb; pdb.set_trace()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u8fd0\u884c\u811a\u672c\u65f6\uff0c\u5f53\u6267\u884c\u5230\u65ad\u70b9\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u6682\u505c\uff0c\u4f60\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u8c03\u8bd5\u547d\u4ee4\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u8c03\u8bd5\u547d\u4ee4<\/strong><\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u8c03\u8bd5\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>n<\/code>\uff08next\uff09\uff1a\u6267\u884c\u4e0b\u4e00\u884c\u4ee3\u7801<\/li>\n<li><code>c<\/code>\uff08continue\uff09\uff1a\u7ee7\u7eed\u6267\u884c\u4ee3\u7801\u76f4\u5230\u4e0b\u4e00\u4e2a\u65ad\u70b9<\/li>\n<li><code>q<\/code>\uff08quit\uff09\uff1a\u9000\u51fa\u8c03\u8bd5\u5668<\/li>\n<li><code>p<\/code>\uff08print\uff09\uff1a\u6253\u5370\u53d8\u91cf\u7684\u503c\uff0c\u4f8b\u5982 <code>p variable<\/code><\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u547d\u4ee4\uff0c\u4f60\u53ef\u4ee5\u68c0\u67e5\u4ee3\u7801\u7684\u6267\u884c\u8fc7\u7a0b\uff0c\u627e\u51fa\u5e76\u4fee\u590d\u9519\u8bef\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e03\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u907f\u514d\u4e0e\u7cfb\u7edfPython\u73af\u5883\u53d1\u751f\u51b2\u7a81\u3002\u4ee5\u4e0b\u662f\u5728\u547d\u4ee4\u884c\u4e2d\u521b\u5efa\u548c\u4f7f\u7528\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u5bfc\u822a\u5230\u4f60\u7684\u9879\u76ee\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>myenv<\/code> \u7684\u865a\u62df\u73af\u5883\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">myenv\\Scripts\\activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Mac\u548cLinux\u7cfb\u7edf\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u4f9d\u8d56\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>pip<\/code> \u547d\u4ee4\u6765\u5b89\u88c5\u4f9d\u8d56\u5e93\u3002\u4f8b\u5982\uff0c\u5b89\u88c5 <code>requests<\/code> \u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u50cf\u4e4b\u524d\u4e00\u6837\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u516b\u3001\u6253\u5305\u548c\u5206\u53d1Python\u9879\u76ee<\/h3>\n<\/p>\n<p><p>\u5f53\u4f60\u5b8c\u6210\u4e86\u4e00\u4e2aPython\u9879\u76ee\uff0c\u53ef\u80fd\u9700\u8981\u5c06\u5176\u6253\u5305\u5e76\u5206\u53d1\u7ed9\u5176\u4ed6\u4eba\u4f7f\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528 setuptools<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a <code>setup.py<\/code> \u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from setuptools import setup, find_packages<\/p>\n<p>setup(<\/p>\n<p>    name=&#39;myproject&#39;,<\/p>\n<p>    version=&#39;0.1&#39;,<\/p>\n<p>    packages=find_packages(),<\/p>\n<p>    install_requires=[<\/p>\n<p>        &#39;requests&#39;,<\/p>\n<p>    ],<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5305\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py sdist<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728 <code>dist<\/code> \u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a <code>.tar.gz<\/code> \u6587\u4ef6\uff0c\u53ef\u4ee5\u5206\u53d1\u7ed9\u5176\u4ed6\u4eba\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528 pip \u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u5c06\u9879\u76ee\u4e0a\u4f20\u5230Python Package Index\uff08PyPI\uff09\uff0c\u5176\u4ed6\u4eba\u53ef\u4ee5\u4f7f\u7528 <code>pip<\/code> \u547d\u4ee4\u6765\u5b89\u88c5\u4f60\u7684\u9879\u76ee\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install myproject<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e5d\u3001\u7f16\u5199\u9ad8\u6548\u7684Python\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u7f16\u5199\u9ad8\u6548\u7684Python\u4ee3\u7801\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6\uff0c\u8fd8\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7f16\u5199\u9ad8\u6548Python\u4ee3\u7801\u7684\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/strong><\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u901a\u5e38\u6bd4\u81ea\u5df1\u7f16\u5199\u7684\u51fd\u6570\u66f4\u9ad8\u6548\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 <code>sum()<\/code> \u8ba1\u7b97\u5217\u8868\u7684\u548c\uff0c\u800c\u4e0d\u662f\u81ea\u5df1\u7f16\u5199\u5faa\u73af\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u9ad8\u6548\u7684\u521b\u5efa\u5217\u8868\u7684\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">squares = [x2 for x in range(10)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97<\/strong><\/p>\n<\/p>\n<p><p>\u907f\u514d\u5728\u5faa\u73af\u4e2d\u8fdb\u884c\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u3002\u4f8b\u5982\uff0c\u5c06\u5faa\u73af\u5916\u90e8\u4e0d\u53d8\u7684\u8ba1\u7b97\u63d0\u5230\u5faa\u73af\u5916\u90e8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u751f\u6210\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u751f\u6210\u5668\u662f\u4e00\u79cd\u9ad8\u6548\u4f7f\u7528\u5185\u5b58\u7684\u8fed\u4ee3\u5668\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def generate_numbers():<\/p>\n<p>    for i in range(10):<\/p>\n<p>        yield i<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784<\/strong><\/p>\n<\/p>\n<p><p>\u6839\u636e\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 <code>set<\/code> \u8fdb\u884c\u5feb\u901f\u6210\u5458\u6d4b\u8bd5\uff0c\u4f7f\u7528 <code>deque<\/code> \u8fdb\u884c\u9ad8\u6548\u7684\u961f\u5217\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u5341\u3001\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u8fd0\u884c\u4e00\u4e2aPython\u6587\u4ef6\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001Python IDLE\u548c\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3002\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u6587\u4ef6\u662f\u6700\u5e38\u7528\u548c\u9ad8\u6548\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u6587\u4ef6\u7684\u6b65\u9aa4\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7f16\u5199\u9ad8\u6548Python\u4ee3\u7801\u7684\u5efa\u8bae\u3002\u5e0c\u671b\u8fd9\u4e9b\u4fe1\u606f\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4e00\u4e2aPython\u811a\u672c\uff1f<\/strong><br \/>\u8981\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4e00\u4e2aPython\u811a\u672c\uff0c\u9996\u5148\u9700\u8981\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u3002\u63a5\u7740\uff0c\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u5b58\u653e.py\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u8f93\u5165<code>python \u6587\u4ef6\u540d.py<\/code>\uff08\u5982\u679c\u4f7f\u7528\u7684\u662fPython 3\uff0c\u53ef\u4ee5\u4f7f\u7528<code>python3 \u6587\u4ef6\u540d.py<\/code>\uff09\u5e76\u6309\u4e0b\u56de\u8f66\u952e\u5373\u53ef\u6267\u884c\u8be5\u811a\u672c\u3002\u786e\u4fdd\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\u5df2\u5b89\u88c5Python\uff0c\u5e76\u4e14\u73af\u5883\u53d8\u91cf\u5df2\u914d\u7f6e\u6b63\u786e\u3002<\/p>\n<p><strong>\u5728IDE\u4e2d\u5982\u4f55\u6267\u884cPython\u6587\u4ef6\uff1f<\/strong><br \/>\u5982\u679c\u4f60\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001VSCode\u6216Jupyter Notebook\uff0c\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u5728IDE\u4e2d\u6253\u5f00.py\u6587\u4ef6\uff0c\u7136\u540e\u70b9\u51fb\u8fd0\u884c\u6309\u94ae\u6765\u6267\u884c\u3002\u5927\u591a\u6570IDE\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u8fd0\u884c\u9009\u9879\uff0c\u8ba9\u4f60\u53ef\u4ee5\u5feb\u901f\u67e5\u770b\u4ee3\u7801\u8f93\u51fa\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5\u4e00\u4e2aPython\u811a\u672c\u4ee5\u786e\u4fdd\u5176\u6b63\u5e38\u8fd0\u884c\uff1f<\/strong><br \/>\u8c03\u8bd5Python\u811a\u672c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528print\u8bed\u53e5\u8f93\u51fa\u53d8\u91cf\u503c\u6765\u8ddf\u8e2a\u4ee3\u7801\u6267\u884c\u8fc7\u7a0b\u3002\u6b64\u5916\uff0cIDE\u901a\u5e38\u5185\u7f6e\u8c03\u8bd5\u5de5\u5177\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u9010\u884c\u6267\u884c\u4ee3\u7801\u548c\u68c0\u67e5\u53d8\u91cf\u72b6\u6001\uff0c\u4ece\u800c\u5e2e\u52a9\u4f60\u627e\u51fa\u6f5c\u5728\u7684\u9519\u8bef\u548c\u95ee\u9898\u3002\u4f7f\u7528<code>try-except<\/code>\u8bed\u53e5\u5904\u7406\u5f02\u5e38\u4e5f\u80fd\u63d0\u9ad8\u4ee3\u7801\u7684\u5065\u58ee\u6027\uff0c\u786e\u4fdd\u5728\u9047\u5230\u9519\u8bef\u65f6\u4e0d\u4f1a\u76f4\u63a5\u5d29\u6e83\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8fd0\u884c\u4e00\u4e2aPython\u6587\u4ef6\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u547d\u4ee4\u884c\u3001IDLE\u3001\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u7b49\u3002\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u547d\u4ee4 [&hellip;]","protected":false},"author":3,"featured_media":1066345,"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\/1066332"}],"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=1066332"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1066332\/revisions"}],"predecessor-version":[{"id":1066346,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1066332\/revisions\/1066346"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1066345"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1066332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1066332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1066332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}