{"id":1133671,"date":"2025-01-08T21:08:36","date_gmt":"2025-01-08T13:08:36","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1133671.html"},"modified":"2025-01-08T21:08:39","modified_gmt":"2025-01-08T13:08:39","slug":"%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e4%bb%a3%e7%a0%81%e6%98%afpython2%e8%bf%98%e6%98%af3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1133671.html","title":{"rendered":"\u5982\u4f55\u5224\u65ad\u4ee3\u7801\u662fpython2\u8fd8\u662f3"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25102839\/2d69751b-809a-41e8-aa69-b5a9b37979c3.webp\" alt=\"\u5982\u4f55\u5224\u65ad\u4ee3\u7801\u662fpython2\u8fd8\u662f3\" \/><\/p>\n<p><p> <strong>\u5224\u65ad\u4ee3\u7801\u662fPython2\u8fd8\u662fPython3<\/strong><br \/><strong>\u67e5\u770bprint\u8bed\u53e5\u3001\u68c0\u67e5\u6574\u6570\u9664\u6cd5\u3001\u89c2\u5bdf\u5b57\u7b26\u4e32\u7f16\u7801<\/strong>\u3002Python2\u548cPython3\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u663e\u8457\u7684\u8bed\u6cd5\u548c\u884c\u4e3a\u5dee\u5f02\uff0c\u8fd9\u4e9b\u5dee\u5f02\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u4ee3\u7801\u662f\u7528\u54ea\u4e2a\u7248\u672c\u7f16\u5199\u7684\u3002<strong>print\u8bed\u53e5<\/strong>\u5728Python2\u4e2d\u662f\u4e00\u4e2a\u8bed\u53e5\uff0c\u800c\u5728Python3\u4e2d\u662f\u4e00\u4e2a\u51fd\u6570\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u4ee3\u7801\u4e2d\u7684print\u8bed\u53e5\u6765\u5feb\u901f\u5224\u65ad\u5b83\u662f\u7528\u54ea\u4e2a\u7248\u672c\u7f16\u5199\u7684\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0cprint\u8bed\u53e5\u5982\u4e0b\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>\u800c\u5728Python3\u4e2d\uff0cprint\u8bed\u53e5\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u9700\u8981\u4f7f\u7528\u62ec\u53f7\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><h3>\u4e00\u3001\u68c0\u67e5print\u8bed\u53e5<\/h3>\n<\/p>\n<p><p>Python2\u548cPython3\u4e4b\u95f4\u6700\u663e\u8457\u7684\u533a\u522b\u4e4b\u4e00\u662fprint\u8bed\u53e5\u7684\u8bed\u6cd5\u3002\u5728Python2\u4e2d\uff0cprint\u662f\u4e00\u4e2a\u8bed\u53e5\uff0c\u4e0d\u9700\u8981\u62ec\u53f7\uff0c\u800c\u5728Python3\u4e2d\uff0cprint\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u5fc5\u987b\u4f7f\u7528\u62ec\u53f7\u3002\u901a\u8fc7\u67e5\u770b\u4ee3\u7801\u4e2d\u7684print\u8bed\u53e5\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u786e\u5b9a\u5b83\u662f\u7528\u54ea\u4e2a\u7248\u672c\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Python2\u7684print\u8bed\u6cd5<\/h4>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0cprint\u8bed\u53e5\u5982\u4e0b\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>\u6ce8\u610f\uff0c\u8fd9\u91cc\u6ca1\u6709\u62ec\u53f7\u3002<\/p>\n<\/p>\n<p><h4>2\u3001Python3\u7684print\u8bed\u6cd5<\/h4>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0cprint\u8bed\u53e5\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u9700\u8981\u4f7f\u7528\u62ec\u53f7\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>\u5982\u679c\u4ee3\u7801\u4e2d\u7684print\u8bed\u53e5\u4f7f\u7528\u4e86\u62ec\u53f7\uff0c\u90a3\u4e48\u5f88\u6709\u53ef\u80fd\u5b83\u662f\u7528Python3\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u6574\u6570\u9664\u6cd5\u7684\u884c\u4e3a<\/h3>\n<\/p>\n<p><p>Python2\u548cPython3\u5728\u5904\u7406\u6574\u6570\u9664\u6cd5\u65f6\u7684\u884c\u4e3a\u4e5f\u4e0d\u540c\u3002\u5728Python2\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u4f1a\u622a\u65ad\u5c0f\u6570\u90e8\u5206\uff0c\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\uff1b\u800c\u5728Python3\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Python2\u7684\u6574\u6570\u9664\u6cd5<\/h4>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u4f1a\u622a\u65ad\u5c0f\u6570\u90e8\u5206\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print 5 \/ 2  # \u8f93\u51fa: 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6ce8\u610f\uff0c\u8fd9\u91cc5\u9664\u4ee52\u7684\u7ed3\u679c\u662f2\uff0c\u800c\u4e0d\u662f2.5\u3002<\/p>\n<\/p>\n<p><h4>2\u3001Python3\u7684\u6574\u6570\u9664\u6cd5<\/h4>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6d6e\u70b9\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(5 \/ 2)  # \u8f93\u51fa: 2.5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4ee3\u7801\u4e2d\u9664\u6cd5\u8fd0\u7b97\u7684\u7ed3\u679c\u603b\u662f\u6574\u6570\uff0c\u90a3\u4e48\u5b83\u5f88\u6709\u53ef\u80fd\u662f\u7528Python2\u7f16\u5199\u7684\uff1b\u5982\u679c\u7ed3\u679c\u662f\u6d6e\u70b9\u6570\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u7528Python3\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5b57\u7b26\u4e32\u7f16\u7801<\/h3>\n<\/p>\n<p><p>Python2\u548cPython3\u5728\u5904\u7406\u5b57\u7b26\u4e32\u7f16\u7801\u65f6\u4e5f\u6709\u663e\u8457\u7684\u533a\u522b\u3002Python2\u6709\u4e24\u79cd\u5b57\u7b26\u4e32\u7c7b\u578b\uff1astr\u548cunicode\uff1b\u800c\u5728Python3\u4e2d\uff0c\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u662funicode\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Python2\u7684\u5b57\u7b26\u4e32\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c\u5b57\u7b26\u4e32\u7c7b\u578b\u5206\u4e3astr\u548cunicode\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">s = &quot;Hello, World!&quot;  # str\u7c7b\u578b<\/p>\n<p>u = u&quot;Hello, World!&quot;  # unicode\u7c7b\u578b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u4f7f\u7528<code>u<\/code>\u524d\u7f00\u6765\u8868\u793aunicode\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><h4>2\u3001Python3\u7684\u5b57\u7b26\u4e32\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0c\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u662funicode\uff0c\u4e0d\u9700\u8981\u4f7f\u7528<code>u<\/code>\u524d\u7f00\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">s = &quot;Hello, World!&quot;  # unicode\u7c7b\u578b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86<code>u<\/code>\u524d\u7f00\u6765\u8868\u793aunicode\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u5b83\u5f88\u6709\u53ef\u80fd\u662f\u7528Python2\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u68c0\u67e5range\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5728Python2\u548cPython3\u4e2d\uff0crange\u51fd\u6570\u7684\u884c\u4e3a\u4e5f\u6709\u6240\u4e0d\u540c\u3002\u5728Python2\u4e2d\uff0crange\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u800c\u5728Python3\u4e2d\uff0crange\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Python2\u7684range\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0crange\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print range(5)  # \u8f93\u51fa: [0, 1, 2, 3, 4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001Python3\u7684range\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0crange\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(range(5))  # \u8f93\u51fa: range(0, 5)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86range\u51fd\u6570\u5e76\u4e14\u671f\u671b\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u90a3\u4e48\u5b83\u5f88\u6709\u53ef\u80fd\u662f\u7528Python2\u7f16\u5199\u7684\uff1b\u5982\u679c\u8fd4\u56de\u7684\u662f\u4e00\u4e2arange\u5bf9\u8c61\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u7528Python3\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u68c0\u67e5\u5f02\u5e38\u5904\u7406\u8bed\u6cd5<\/h3>\n<\/p>\n<p><p>Python2\u548cPython3\u5728\u5f02\u5e38\u5904\u7406\u8bed\u6cd5\u4e0a\u4e5f\u6709\u6240\u4e0d\u540c\u3002\u5728Python2\u4e2d\uff0c\u4f7f\u7528<code>as<\/code>\u5173\u952e\u5b57\u6765\u6355\u83b7\u5f02\u5e38\u4fe1\u606f\uff1b\u800c\u5728Python3\u4e2d\uff0c\u4f7f\u7528<code>as<\/code>\u5173\u952e\u5b57\u6765\u6355\u83b7\u5f02\u5e38\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Python2\u7684\u5f02\u5e38\u5904\u7406\u8bed\u6cd5<\/h4>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c\u5f02\u5e38\u5904\u7406\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    # \u4ee3\u7801\u5757<\/p>\n<p>except Exception, e:<\/p>\n<p>    print &quot;Error:&quot;, e<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u4f7f\u7528\u9017\u53f7\u6765\u6355\u83b7\u5f02\u5e38\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h4>2\u3001Python3\u7684\u5f02\u5e38\u5904\u7406\u8bed\u6cd5<\/h4>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0c\u5f02\u5e38\u5904\u7406\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    # \u4ee3\u7801\u5757<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(&quot;Error:&quot;, e)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u4f7f\u7528<code>as<\/code>\u5173\u952e\u5b57\u6765\u6355\u83b7\u5f02\u5e38\u4fe1\u606f\u3002\u5982\u679c\u4ee3\u7801\u4e2d\u7684\u5f02\u5e38\u5904\u7406\u8bed\u6cd5\u4f7f\u7528\u4e86\u9017\u53f7\uff0c\u90a3\u4e48\u5b83\u5f88\u6709\u53ef\u80fd\u662f\u7528Python2\u7f16\u5199\u7684\uff1b\u5982\u679c\u4f7f\u7528\u4e86<code>as<\/code>\u5173\u952e\u5b57\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u7528Python3\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u6a21\u5757\u540d\u79f0\u7684\u53d8\u5316<\/h3>\n<\/p>\n<p><p>Python2\u548cPython3\u4e2d\u4e00\u4e9b\u6807\u51c6\u5e93\u6a21\u5757\u7684\u540d\u79f0\u4e5f\u6709\u6240\u4e0d\u540c\u3002\u4f8b\u5982\uff0cPython2\u4e2d\u7684<code>urllib<\/code>\u6a21\u5757\u5728Python3\u4e2d\u88ab\u62c6\u5206\u6210\u4e86\u51e0\u4e2a\u5b50\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Python2\u7684urllib\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c<code>urllib<\/code>\u6a21\u5757\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import urllib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001Python3\u7684urllib\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0c<code>urllib<\/code>\u6a21\u5757\u88ab\u62c6\u5206\u6210\u4e86\u51e0\u4e2a\u5b50\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import urllib.request<\/p>\n<p>import urllib.parse<\/p>\n<p>import urllib.error<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86\u65e7\u7684\u6a21\u5757\u540d\u79f0\uff0c\u90a3\u4e48\u5b83\u5f88\u6709\u53ef\u80fd\u662f\u7528Python2\u7f16\u5199\u7684\uff1b\u5982\u679c\u4f7f\u7528\u4e86\u65b0\u7684\u6a21\u5757\u540d\u79f0\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u7528Python3\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u75282to3\u5de5\u5177<\/h3>\n<\/p>\n<p><p>Python\u5b98\u65b9\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3a<code>2to3<\/code>\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u81ea\u52a8\u5c06Python2\u4ee3\u7801\u8f6c\u6362\u4e3aPython3\u4ee3\u7801\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u5de5\u5177\u6765\u68c0\u67e5\u4ee3\u7801\u662f\u7528\u54ea\u4e2a\u7248\u672c\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c52to3\u5de5\u5177<\/h4>\n<\/p>\n<p><p><code>2to3<\/code>\u5de5\u5177\u901a\u5e38\u968fPython\u5b89\u88c5\u5305\u4e00\u8d77\u5b89\u88c5\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install 2to3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u75282to3\u5de5\u5177<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>2to3<\/code>\u5de5\u5177\u68c0\u67e5\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">2to3 -w your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c<code>2to3<\/code>\u5de5\u5177\u62a5\u544a\u4e86\u5f88\u591a\u9700\u8981\u4fee\u6539\u7684\u5730\u65b9\uff0c\u90a3\u4e48\u4ee3\u7801\u5f88\u6709\u53ef\u80fd\u662f\u7528Python2\u7f16\u5199\u7684\uff1b\u5982\u679c\u6ca1\u6709\u62a5\u544a\u592a\u591a\u9700\u8981\u4fee\u6539\u7684\u5730\u65b9\uff0c\u90a3\u4e48\u4ee3\u7801\u53ef\u80fd\u662f\u7528Python3\u7f16\u5199\u7684\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5224\u65ad\u4ee3\u7801\u662fPython2\u8fd8\u662fPython3\u7f16\u5199\u7684\uff0c\u53ef\u4ee5\u901a\u8fc7\u67e5\u770bprint\u8bed\u53e5\u3001\u6574\u6570\u9664\u6cd5\u7684\u884c\u4e3a\u3001\u5b57\u7b26\u4e32\u7f16\u7801\u3001range\u51fd\u6570\u3001\u5f02\u5e38\u5904\u7406\u8bed\u6cd5\u3001\u6a21\u5757\u540d\u79f0\u7684\u53d8\u5316\u4ee5\u53ca\u4f7f\u75282to3\u5de5\u5177\u6765\u8fdb\u884c\u5224\u65ad\u3002<strong>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5feb\u901f\u51c6\u786e\u5730\u786e\u5b9a\u4ee3\u7801\u7684Python\u7248\u672c<\/strong>\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7efc\u5408\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5224\u65ad\u4ee3\u7801\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u8bc6\u522bPython\u4ee3\u7801\u7684\u7248\u672c\uff1f<\/strong><br \/>\u8981\u5224\u65ad\u4e00\u6bb5\u4ee3\u7801\u662fPython 2\u8fd8\u662fPython 3\uff0c\u9996\u5148\u53ef\u4ee5\u89c2\u5bdf\u4ee3\u7801\u4e2d\u5e38\u7528\u7684\u8bed\u6cd5\u7279\u5f81\u3002\u4f8b\u5982\uff0cPython 3\u4e2d\u4f7f\u7528<code>print()<\/code>\u4f5c\u4e3a\u51fd\u6570\uff0c\u800c\u5728Python 2\u4e2d\uff0c<code>print<\/code>\u662f\u4e00\u4e2a\u8bed\u53e5\u3002\u6b64\u5916\uff0cPython 3\u7684\u5b57\u7b26\u4e32\u5904\u7406\u65b9\u9762\u66f4\u52a0\u4e25\u683c\uff0c\u7279\u522b\u662f\u5bf9Unicode\u7684\u652f\u6301\u3002\u4f60\u53ef\u4ee5\u67e5\u627e\u8fd9\u4e9b\u7279\u5f81\u6765\u521d\u6b65\u5224\u65ad\u4ee3\u7801\u7684\u7248\u672c\u3002<\/p>\n<p><strong>\u4f7f\u7528\u54ea\u4e9b\u5de5\u5177\u53ef\u4ee5\u81ea\u52a8\u68c0\u6d4bPython\u4ee3\u7801\u7248\u672c\uff1f<\/strong><br \/>\u6709\u4e00\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u4f60\u81ea\u52a8\u68c0\u6d4b\u4ee3\u7801\u7684\u7248\u672c\u3002\u4f8b\u5982\uff0c<code>pylint<\/code>\u548c<code>pyflakes<\/code>\u7b49\u9759\u6001\u5206\u6790\u5de5\u5177\u80fd\u591f\u5206\u6790\u4ee3\u7801\u5e76\u7ed9\u51fa\u7248\u672c\u517c\u5bb9\u6027\u5efa\u8bae\u3002\u6b64\u5916\uff0c<code>2to3<\/code>\u5de5\u5177\u53ef\u4ee5\u5c06Python 2\u7684\u4ee3\u7801\u8f6c\u6362\u4e3aPython 3\u7684\u4ee3\u7801\uff0c\u5b83\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u4f1a\u63d0\u9192\u4f60\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86\u54ea\u4e9bPython 2\u7279\u6709\u7684\u7279\u6027\u3002<\/p>\n<p><strong>\u5728\u8fd0\u884c\u4ee3\u7801\u65f6\u5982\u4f55\u786e\u5b9a\u5176\u4f7f\u7528\u7684Python\u7248\u672c\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u7279\u5b9a\u7684\u547d\u4ee4\u6765\u68c0\u67e5\u5f53\u524d\u7684Python\u7248\u672c\u3002\u6bd4\u5982\uff0c\u4f7f\u7528<code>import sys<\/code>\u548c<code>print(sys.version)<\/code>\u53ef\u4ee5\u8f93\u51fa\u5f53\u524d\u73af\u5883\u4e2dPython\u7684\u7248\u672c\u4fe1\u606f\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728\u8c03\u8bd5\u6216\u786e\u4fdd\u517c\u5bb9\u6027\u65f6\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u578b\u9879\u76ee\u65f6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5224\u65ad\u4ee3\u7801\u662fPython2\u8fd8\u662fPython3\u67e5\u770bprint\u8bed\u53e5\u3001\u68c0\u67e5\u6574\u6570\u9664\u6cd5\u3001\u89c2\u5bdf\u5b57\u7b26\u4e32\u7f16\u7801\u3002Python2\u548cP [&hellip;]","protected":false},"author":3,"featured_media":1133678,"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\/1133671"}],"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=1133671"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1133671\/revisions"}],"predecessor-version":[{"id":1133681,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1133671\/revisions\/1133681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1133678"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1133671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1133671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1133671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}