{"id":948770,"date":"2024-12-27T00:06:39","date_gmt":"2024-12-26T16:06:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/948770.html"},"modified":"2024-12-27T00:06:41","modified_gmt":"2024-12-26T16:06:41","slug":"%e5%a6%82%e4%bd%95%e5%8c%ba%e5%88%86python2-python3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/948770.html","title":{"rendered":"\u5982\u4f55\u533a\u5206Python2 Python3"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084015\/28a7b20a-57b9-4726-80db-e38337f94ddd.webp\" alt=\"\u5982\u4f55\u533a\u5206Python2 Python3\" \/><\/p>\n<p><p> <strong>\u533a\u5206Python2\u548cPython3\u7684\u5173\u952e\u70b9\u5305\u62ec\uff1a\u8bed\u6cd5\u5dee\u5f02\u3001\u5e93\u652f\u6301\u3001\u5b57\u7b26\u4e32\u5904\u7406\u3001\u6574\u6570\u9664\u6cd5\u3001\u8f93\u5165\u8f93\u51fa\u51fd\u6570\u3001Unicode\u652f\u6301\u3001\u9519\u8bef\u5904\u7406\u3001\u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668\u3001\u7c7b\u5b9a\u4e49\u3001\u5f02\u5e38\u5904\u7406<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u8bed\u6cd5\u5dee\u5f02<\/strong>\u662f\u6700\u663e\u8457\u7684\u7279\u70b9\uff0cPython3\u5f15\u5165\u4e86\u8bb8\u591aPython2\u4e2d\u6ca1\u6709\u7684\u65b0\u7279\u6027\u548c\u66f4\u4e25\u683c\u7684\u8bed\u6cd5\u89c4\u5219\u3002\u4f8b\u5982\uff0cPython3\u8981\u6c42\u4f7f\u7528\u62ec\u53f7\u6765\u8c03\u7528print\u51fd\u6570\uff0c\u800c\u5728Python2\u4e2d\uff0cprint\u662f\u4e00\u4e2a\u8bed\u53e5\uff0c\u4e0d\u9700\u8981\u62ec\u53f7\u3002<\/p>\n<\/p>\n<p><p>Python3\u76f8\u8f83\u4e8ePython2\u5728\u8bed\u6cd5\u4e0a\u66f4\u4e3a\u4e25\u683c\u548c\u4e00\u81f4\uff0c\u8fd9\u6709\u52a9\u4e8e\u51cf\u5c11\u7f16\u7a0b\u9519\u8bef\u5e76\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002\u4f8b\u5982\uff0cPython3\u4e2d\u7684print\u662f\u4e00\u79cd\u51fd\u6570\uff0c\u800c\u5728Python2\u4e2d\uff0cprint\u662f\u4e00\u79cd\u8bed\u53e5\u3002\u8fd9\u4e00\u6539\u53d8\u4e0d\u4ec5\u4f7f\u5f97\u4ee3\u7801\u66f4\u5177\u4e00\u81f4\u6027\uff0c\u8fd8\u4e3aprint\u51fd\u6570\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\u548c\u7075\u6d3b\u6027\uff0c\u4f8b\u5982\u652f\u6301\u591a\u884c\u6253\u5370\u3001\u901a\u8fc7\u5173\u952e\u5b57\u53c2\u6570\u6307\u5b9a\u5206\u9694\u7b26\u7b49\u3002\u6b64\u5916\uff0cPython3\u5728\u5904\u7406\u9519\u8bef\u65f6\u63d0\u4f9b\u4e86\u66f4\u8be6\u7ec6\u7684\u5f02\u5e38\u4fe1\u606f\uff0c\u4f7f\u5f97\u8c03\u8bd5\u8fc7\u7a0b\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u8bed\u6cd5\u5dee\u5f02<\/p>\n<\/p>\n<p><p>Python2\u548cPython3\u5728\u8bed\u6cd5\u4e0a\u6709\u8bb8\u591a\u4e0d\u540c\u4e4b\u5904\uff0c\u6700\u663e\u8457\u7684\u5c31\u662fprint\u7684\u4f7f\u7528\u3002\u5728Python2\u4e2d\uff0cprint\u662f\u4e00\u4e2a\u8bed\u53e5\uff0c\u4e0d\u9700\u8981\u62ec\u53f7\uff0c\u800c\u5728Python3\u4e2d\uff0cprint\u88ab\u6539\u4e3a\u4e00\u4e2a\u51fd\u6570\uff0c\u9700\u8981\u4f7f\u7528\u62ec\u53f7\u3002\u6b64\u5916\uff0c\u5728Python3\u4e2d\uff0c\u6574\u9664\u8fd0\u7b97\u7b26\u201c\/\u201d\u8fd4\u56de\u6d6e\u70b9\u6570\uff0c\u800c\u5728Python2\u4e2d\uff0c\u5b83\u8fd4\u56de\u6574\u6570\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>Python3\u7684\u8bed\u6cd5\u66f4\u4e3a\u4e25\u683c\u548c\u4e00\u81f4\uff0c\u8fd9\u5728\u7f16\u7a0b\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u51cf\u5c11\u8bb8\u591a\u6f5c\u5728\u7684\u9519\u8bef\u3002\u4f8b\u5982\uff0cPython3\u8981\u6c42\u5728\u8c03\u7528\u51fd\u6570\u65f6\u5fc5\u987b\u4f7f\u7528\u62ec\u53f7\uff0c\u8fd9\u4e0d\u4ec5\u4f7f\u5f97\u8bed\u6cd5\u66f4\u52a0\u6e05\u6670\uff0c\u4e5f\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u4e00\u81f4\u6027\u3002\u6b64\u5916\uff0cPython3\u5bf9\u7f29\u8fdb\u7684\u8981\u6c42\u66f4\u52a0\u4e25\u683c\uff0c\u8fd9\u4e5f\u662f\u4e3a\u4e86\u786e\u4fdd\u4ee3\u7801\u7684\u7ed3\u6784\u6e05\u6670\uff0c\u4ece\u800c\u51cf\u5c11\u8c03\u8bd5\u7684\u96be\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5e93\u652f\u6301<\/p>\n<\/p>\n<p><p>\u8bb8\u591a\u65b0\u7684Python\u5e93\u548c\u6846\u67b6\u4ec5\u652f\u6301Python3\uff0c\u8fd9\u4f7f\u5f97Python3\u6210\u4e3a\u8bb8\u591a\u65b0\u9879\u76ee\u7684\u9996\u9009\u8bed\u8a00\u3002Python2\u57282015\u5e74\u5df2\u7ecf\u505c\u6b62\u4e86\u5b98\u65b9\u652f\u6301\uff0c\u56e0\u6b64\u65b0\u7684\u529f\u80fd\u548c\u66f4\u65b0\u53ea\u4f1a\u51fa\u73b0\u5728Python3\u4e2d\u3002\u8fd9\u610f\u5473\u7740Python3\u5728\u6027\u80fd\u548c\u529f\u80fd\u4e0a\u901a\u5e38\u4f18\u4e8ePython2\u3002<\/p>\n<\/p>\n<p><p>Python3\u5728\u5e93\u652f\u6301\u65b9\u9762\u6709\u660e\u663e\u7684\u4f18\u52bf\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u6570\u636e\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u548c<a href=\"https:\/\/docs.pingcode.com\/tag\/AI\" target=\"_blank\">\u4eba\u5de5\u667a\u80fd<\/a>\u7b49\u65b0\u5174\u9886\u57df\u3002\u7531\u4e8ePython3\u7684\u66f4\u65b0\u901f\u5ea6\u8f83\u5feb\uff0c\u8bb8\u591a\u65b0\u5e93\u548c\u6846\u67b6\u90fd\u4f18\u5148\u652f\u6301Python3\u3002\u8fd9\u4e0d\u4ec5\u4f7f\u5f97Python3\u7684\u751f\u6001\u7cfb\u7edf\u66f4\u52a0\u4e30\u5bcc\uff0c\u4e5f\u63a8\u52a8\u4e86Python3\u5728\u5404\u79cd\u5e94\u7528\u573a\u666f\u4e2d\u7684\u5e7f\u6cdb\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5b57\u7b26\u4e32\u5904\u7406<\/p>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c\u5b57\u7b26\u4e32\u6709\u4e24\u79cd\u7c7b\u578b\uff1astr\u548cunicode\uff0c\u800c\u5728Python3\u4e2d\uff0c\u5b57\u7b26\u4e32\u9ed8\u8ba4\u662funicode\u7c7b\u578b\u3002\u8fd9\u4f7f\u5f97Python3\u5728\u5904\u7406\u56fd\u9645\u5316\u5b57\u7b26\u65f6\u66f4\u52a0\u65b9\u4fbf\u548c\u4e00\u81f4\u3002\u5728Python2\u4e2d\uff0c\u5904\u7406\u975eASCII\u5b57\u7b26\u901a\u5e38\u9700\u8981\u989d\u5916\u7684\u7f16\u7801\u8f6c\u6362\uff0c\u800c\u5728Python3\u4e2d\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u66f4\u52a0\u76f4\u89c2\u3002<\/p>\n<\/p>\n<p><p>Python3\u5bf9\u5b57\u7b26\u4e32\u7684\u5904\u7406\u66f4\u52a0\u4f18\u96c5\u548c\u9ad8\u6548\uff0c\u5c24\u5176\u662f\u5728\u591a\u8bed\u8a00\u73af\u5883\u4e0b\u3002\u7531\u4e8ePython3\u9ed8\u8ba4\u4f7f\u7528unicode\uff0c\u8fd9\u4f7f\u5f97\u5904\u7406\u5404\u79cd\u8bed\u8a00\u7684\u6587\u672c\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u548c\u76f4\u63a5\u3002\u6b64\u5916\uff0cPython3\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u65b0\u7684\u5b57\u7b26\u4e32\u65b9\u6cd5\u548c\u683c\u5f0f\u5316\u9009\u9879\uff0c\u4f7f\u5f97\u5b57\u7b26\u4e32\u64cd\u4f5c\u66f4\u52a0\u7075\u6d3b\u548c\u5f3a\u5927\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u6574\u6570\u9664\u6cd5<\/p>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u9ed8\u8ba4\u8fd4\u56de\u6574\u6570\uff0c\u8fd9\u5e38\u5e38\u4f1a\u5bfc\u81f4\u610f\u5916\u7684\u7ed3\u679c\u3002\u5728Python3\u4e2d\uff0c\u6574\u6570\u9664\u6cd5\u8fd4\u56de\u6d6e\u70b9\u6570\uff0c\u8fd9\u4f7f\u5f97\u8ba1\u7b97\u7ed3\u679c\u66f4\u52a0\u51c6\u786e\u3002\u5982\u679c\u9700\u8981\u6574\u6570\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\/\/\u201d\u8fd0\u7b97\u7b26\u3002<\/p>\n<\/p>\n<p><p>Python3\u5bf9\u6574\u6570\u9664\u6cd5\u7684\u5904\u7406\u66f4\u52a0\u7b26\u5408\u6570\u5b66\u76f4\u89c9\uff0c\u8fd9\u5728\u8bb8\u591a\u5e94\u7528\u573a\u666f\u4e2d\u53ef\u4ee5\u51cf\u5c11\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u5728Python2\u4e2d\uff0c5\/2\u4f1a\u8fd4\u56de2\uff0c\u800c\u5728Python3\u4e2d\uff0c5\/2\u4f1a\u8fd4\u56de2.5\uff0c\u8fd9\u66f4\u7b26\u5408\u4eba\u4eec\u7684\u671f\u671b\u3002\u6b64\u5916\uff0cPython3\u7684\u201c\/\/\u201d\u8fd0\u7b97\u7b26\u53ef\u4ee5\u660e\u786e\u8868\u793a\u9700\u8981\u6574\u6570\u7ed3\u679c\uff0c\u8fd9\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u548c\u6613\u4e8e\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u8f93\u5165\u8f93\u51fa\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u5728Python2\u4e2d\uff0craw_input()\u51fd\u6570\u7528\u4e8e\u63a5\u6536\u7528\u6237\u8f93\u5165\uff0c\u800c\u5728Python3\u4e2d\uff0c\u8fd9\u4e2a\u51fd\u6570\u88ab\u91cd\u547d\u540d\u4e3ainput()\u3002Python3\u7684input()\u51fd\u6570\u603b\u662f\u8fd4\u56de\u5b57\u7b26\u4e32\uff0c\u56e0\u6b64\u9700\u8981\u663e\u5f0f\u5730\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><p>Python3\u5728\u8f93\u5165\u8f93\u51fa\u51fd\u6570\u65b9\u9762\u7684\u6539\u8fdb\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u76f4\u89c2\u548c\u6613\u4e8e\u7406\u89e3\u3002\u7531\u4e8einput()\u51fd\u6570\u603b\u662f\u8fd4\u56de\u5b57\u7b26\u4e32\uff0c\u8fd9\u51cf\u5c11\u4e86\u8bb8\u591a\u6f5c\u5728\u7684\u7c7b\u578b\u9519\u8bef\u3002\u6b64\u5916\uff0cPython3\u8fd8\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u8f93\u5165\u8f93\u51fa\u9009\u9879\u548c\u683c\u5f0f\u5316\u65b9\u6cd5\uff0c\u4f7f\u5f97\u7528\u6237\u4ea4\u4e92\u66f4\u52a0\u7075\u6d3b\u548c\u5f3a\u5927\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001Unicode\u652f\u6301<\/p>\n<\/p>\n<p><p>Python3\u5bf9Unicode\u7684\u652f\u6301\u6bd4Python2\u66f4\u52a0\u5168\u9762\u548c\u4e00\u81f4\u3002\u5728Python3\u4e2d\uff0c\u6240\u6709\u5b57\u7b26\u4e32\u9ed8\u8ba4\u662fUnicode\uff0c\u8fd9\u4f7f\u5f97\u5904\u7406\u56fd\u9645\u5316\u5b57\u7b26\u66f4\u52a0\u7b80\u5355\u3002\u5728Python2\u4e2d\uff0c\u9700\u8981\u663e\u5f0f\u5730\u6307\u5b9aUnicode\u5b57\u7b26\u4e32\uff0c\u8fd9\u5e38\u5e38\u5bfc\u81f4\u7f16\u7801\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><p>Python3\u7684Unicode\u652f\u6301\u4f7f\u5f97\u591a\u8bed\u8a00\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u3002\u7531\u4e8e\u5b57\u7b26\u4e32\u9ed8\u8ba4\u662fUnicode\uff0c\u5f00\u53d1\u8005\u4e0d\u9700\u8981\u62c5\u5fc3\u5b57\u7b26\u7f16\u7801\u95ee\u9898\uff0c\u8fd9\u5927\u5927\u7b80\u5316\u4e86\u591a\u8bed\u8a00\u6587\u672c\u5904\u7406\u3002\u6b64\u5916\uff0cPython3\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591aUnicode\u76f8\u5173\u7684\u5de5\u5177\u548c\u51fd\u6570\uff0c\u4f7f\u5f97\u56fd\u9645\u5316\u5f00\u53d1\u66f4\u52a0\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u9519\u8bef\u5904\u7406<\/p>\n<\/p>\n<p><p>Python3\u5728\u9519\u8bef\u5904\u7406\u65b9\u9762\u63d0\u4f9b\u4e86\u66f4\u8be6\u7ec6\u7684\u5f02\u5e38\u4fe1\u606f\uff0c\u8fd9\u4f7f\u5f97\u8c03\u8bd5\u8fc7\u7a0b\u66f4\u52a0\u9ad8\u6548\u3002\u5728Python2\u4e2d\uff0c\u5f02\u5e38\u4fe1\u606f\u5f80\u5f80\u4e0d\u591f\u8be6\u7ec6\uff0c\u96be\u4ee5\u5b9a\u4f4d\u95ee\u9898\u7684\u6839\u6e90\u3002Python3\u5f15\u5165\u4e86\u66f4\u591a\u7684\u5f02\u5e38\u7c7b\u578b\u548c\u66f4\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u8fd9\u6709\u52a9\u4e8e\u5feb\u901f\u627e\u5230\u5e76\u4fee\u590d\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p>Python3\u5728\u9519\u8bef\u5904\u7406\u65b9\u9762\u7684\u6539\u8fdb\u4f7f\u5f97\u5f00\u53d1\u8005\u80fd\u591f\u66f4\u5feb\u5730\u89e3\u51b3\u95ee\u9898\u3002\u901a\u8fc7\u66f4\u8be6\u7ec6\u7684\u5f02\u5e38\u4fe1\u606f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u51c6\u786e\u5730\u5b9a\u4f4d\u95ee\u9898\u7684\u6839\u6e90\uff0c\u4ece\u800c\u51cf\u5c11\u8c03\u8bd5\u65f6\u95f4\u3002\u6b64\u5916\uff0cPython3\u7684\u5f02\u5e38\u7c7b\u578b\u66f4\u52a0\u4e30\u5bcc\uff0c\u8fd9\u4f7f\u5f97\u9519\u8bef\u5904\u7406\u66f4\u52a0\u7075\u6d3b\u548c\u5f3a\u5927\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668<\/p>\n<\/p>\n<p><p>Python3\u5bf9\u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668\u7684\u652f\u6301\u66f4\u52a0\u5b8c\u5584\u3002\u5728Python3\u4e2d\uff0c\u8bb8\u591a\u5185\u7f6e\u51fd\u6570\u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u800c\u4e0d\u662f\u5217\u8868\uff0c\u8fd9\u63d0\u9ad8\u4e86\u5185\u5b58\u6548\u7387\u3002\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u5728Python3\u4e2d\u4e5f\u53d8\u5f97\u66f4\u52a0\u5f3a\u5927\u548c\u7075\u6d3b\u3002<\/p>\n<\/p>\n<p><p>Python3\u5bf9\u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668\u7684\u4f18\u5316\u4f7f\u5f97\u5904\u7406\u5927\u6570\u636e\u96c6\u53d8\u5f97\u66f4\u52a0\u9ad8\u6548\u3002\u7531\u4e8e\u8bb8\u591a\u51fd\u6570\u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u8fd9\u51cf\u5c11\u4e86\u5185\u5b58\u4f7f\u7528\uff0c\u4f7f\u5f97\u7a0b\u5e8f\u80fd\u591f\u5904\u7406\u66f4\u5927\u7684\u6570\u636e\u96c6\u3002\u6b64\u5916\uff0c\u751f\u6210\u5668\u7684\u7075\u6d3b\u6027\u4f7f\u5f97\u6d41\u5f0f\u6570\u636e\u5904\u7406\u66f4\u52a0\u7b80\u5355\u548c\u76f4\u89c2\u3002<\/p>\n<\/p>\n<p><p>\u4e5d\u3001\u7c7b\u5b9a\u4e49<\/p>\n<\/p>\n<p><p>\u5728Python3\u4e2d\uff0c\u6240\u6709\u7c7b\u9ed8\u8ba4\u90fd\u662f\u65b0\u5f0f\u7c7b\uff0c\u800c\u5728Python2\u4e2d\uff0c\u5fc5\u987b\u663e\u5f0f\u5730\u7ee7\u627fobject\u7c7b\u624d\u80fd\u5b9a\u4e49\u65b0\u5f0f\u7c7b\u3002\u65b0\u5f0f\u7c7b\u5177\u6709\u66f4\u597d\u7684\u7279\u6027\u548c\u529f\u80fd\uff0c\u4f8b\u5982\u652f\u6301\u591a\u91cd\u7ee7\u627f\u548c\u63cf\u8ff0\u7b26\u3002<\/p>\n<\/p>\n<p><p>Python3\u5728\u7c7b\u5b9a\u4e49\u65b9\u9762\u7684\u7edf\u4e00\u6027\u4f7f\u5f97\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u66f4\u52a0\u81ea\u7136\u548c\u5f3a\u5927\u3002\u7531\u4e8e\u6240\u6709\u7c7b\u9ed8\u8ba4\u90fd\u662f\u65b0\u5f0f\u7c7b\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u5229\u7528\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u9ad8\u7ea7\u7279\u6027\u3002\u6b64\u5916\uff0cPython3\u7684\u7c7b\u673a\u5236\u66f4\u52a0\u5b8c\u5584\uff0c\u8fd9\u4f7f\u5f97\u4ee3\u7801\u7684\u6a21\u5757\u5316\u548c\u91cd\u7528\u6027\u66f4\u5f3a\u3002<\/p>\n<\/p>\n<p><p>\u5341\u3001\u5f02\u5e38\u5904\u7406<\/p>\n<\/p>\n<p><p>Python3\u5bf9\u5f02\u5e38\u5904\u7406\u7684\u8bed\u6cd5\u8fdb\u884c\u4e86\u6539\u8fdb\uff0c\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u3002\u5728Python3\u4e2d\uff0cexcept\u8bed\u53e5\u5fc5\u987b\u4f7f\u7528as\u5173\u952e\u5b57\u6765\u6355\u83b7\u5f02\u5e38\uff0c\u800c\u5728Python2\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u9017\u53f7\u3002\u8fd9\u4e00\u53d8\u5316\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u5e76\u51cf\u5c11\u4e86\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><p>Python3\u5728\u5f02\u5e38\u5904\u7406\u65b9\u9762\u7684\u6539\u8fdb\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u5065\u58ee\u548c\u6613\u4e8e\u7ef4\u62a4\u3002\u901a\u8fc7\u4f7f\u7528as\u5173\u952e\u5b57\uff0c\u5f02\u5e38\u6355\u83b7\u7684\u8bed\u6cd5\u66f4\u52a0\u4e00\u81f4\u548c\u6e05\u6670\uff0c\u8fd9\u51cf\u5c11\u4e86\u8bb8\u591a\u6f5c\u5728\u7684\u9519\u8bef\u3002\u6b64\u5916\uff0cPython3\u8fd8\u5f15\u5165\u4e86\u66f4\u591a\u7684\u5f02\u5e38\u7c7b\u578b\uff0c\u4f7f\u5f97\u9519\u8bef\u5904\u7406\u66f4\u52a0\u7075\u6d3b\u548c\u5f3a\u5927\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0cPython2\u548cPython3\u5728\u591a\u4e2a\u65b9\u9762\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002Python3\u5728\u8bed\u6cd5\u3001\u6027\u80fd\u548c\u529f\u80fd\u4e0a\u90fd\u4f18\u4e8ePython2\uff0c\u8fd9\u4f7f\u5f97\u5b83\u6210\u4e3a\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u7684\u9996\u9009\u8bed\u8a00\u3002\u901a\u8fc7\u7406\u89e3\u8fd9\u4e9b\u5dee\u5f02\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u9009\u62e9\u5408\u9002\u7684Python\u7248\u672c\uff0c\u5e76\u7f16\u5199\u9ad8\u6548\u3001\u53ef\u9760\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5224\u65ad\u6211\u7684\u4ee3\u7801\u9002\u7528\u4e8ePython2\u8fd8\u662fPython3\uff1f<\/strong><br \/>\u8981\u5224\u65ad\u4e00\u6bb5\u4ee3\u7801\u9002\u7528\u4e8e\u54ea\u4e2a\u7248\u672c\u7684Python\uff0c\u9996\u5148\u9700\u8981\u5173\u6ce8\u8bed\u6cd5\u548c\u5e93\u7684\u4f7f\u7528\u3002Python2\u548cPython3\u5728\u5904\u7406\u5b57\u7b26\u4e32\u3001print\u8bed\u53e5\u3001\u5f02\u5e38\u5904\u7406\u7b49\u65b9\u9762\u6709\u663e\u8457\u5dee\u5f02\u3002\u4f8b\u5982\uff0cPython2\u4f7f\u7528print\u8bed\u53e5\uff0c\u800cPython3\u4f7f\u7528print()\u51fd\u6570\u3002\u6b64\u5916\uff0c\u5b57\u7b26\u4e32\u5904\u7406\u65b9\u9762\uff0cPython3\u5f15\u5165\u4e86Unicode\u5b57\u7b26\u4e32\u7684\u6982\u5ff5\uff0c\u4f7f\u7528\u65b9\u5f0f\u4e5f\u6709\u6240\u4e0d\u540c\u3002\u901a\u8fc7\u67e5\u770b\u4ee3\u7801\u4e2d\u662f\u5426\u5305\u542b\u8fd9\u4e9b\u7279\u5f81\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u786e\u5b9a\u5176\u9002\u7528\u7684Python\u7248\u672c\u3002<\/p>\n<p><strong>\u5728Python2\u548cPython3\u4e4b\u95f4\u8fc1\u79fb\u4ee3\u7801\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u5173\u952e\u70b9\uff1f<\/strong><br \/>\u8fc1\u79fb\u4ee3\u7801\u65f6\uff0c\u6709\u51e0\u4e2a\u91cd\u8981\u7684\u65b9\u9762\u9700\u8981\u7279\u522b\u5173\u6ce8\u3002\u9996\u5148\uff0c\u5b57\u7b26\u4e32\u7684\u5904\u7406\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\uff0c\u7279\u522b\u662f\u5728\u5b57\u8282\u548cUnicode\u4e4b\u95f4\u7684\u8f6c\u6362\u3002\u5176\u6b21\uff0cPython3\u4e2d\u53bb\u9664\u4e86\u67d0\u4e9bPython2\u4e2d\u7684\u6a21\u5757\u548c\u51fd\u6570\uff0c\u6bd4\u5982<code>raw_input()<\/code>\u5728Python3\u4e2d\u88ab\u66ff\u6362\u4e3a<code>input()<\/code>\u3002\u6b64\u5916\uff0c\u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668\u7684\u4f7f\u7528\u5728\u8fd9\u4e24\u4e2a\u7248\u672c\u95f4\u4e5f\u6709\u6240\u4e0d\u540c\uff0c\u786e\u4fdd\u60a8\u4e86\u89e3\u8fd9\u4e9b\u53d8\u5316\u5c06\u6709\u52a9\u4e8e\u987a\u5229\u8fc1\u79fb\u4ee3\u7801\u3002<\/p>\n<p><strong>\u5728\u54ea\u91cc\u53ef\u4ee5\u627e\u5230Python2\u4e0ePython3\u7684\u4e3b\u8981\u5dee\u5f02\u5217\u8868\uff1f<\/strong><br \/>\u6709\u8bb8\u591a\u5728\u7ebf\u8d44\u6e90\u548c\u5b98\u65b9\u6587\u6863\u53ef\u4ee5\u5e2e\u52a9\u60a8\u4e86\u89e3Python2\u548cPython3\u4e4b\u95f4\u7684\u5dee\u5f02\u3002Python\u5b98\u65b9\u7f51\u7ad9\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684<a href=\"https:\/\/docs.python.org\/3\/whatsnew\/3.0.html\">Python 2\u548cPython 3\u7684\u5dee\u5f02<\/a>\u5217\u8868\uff0c\u60a8\u53ef\u4ee5\u5728\u8fd9\u91cc\u627e\u5230\u6709\u5173\u8bed\u6cd5\u3001\u5e93\u3001\u5185\u7f6e\u51fd\u6570\u7b49\u65b9\u9762\u7684\u5177\u4f53\u4fe1\u606f\u3002\u6b64\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5f00\u6e90\u9879\u76ee\u548c\u793e\u533a\u8bba\u575b\uff0c\u63d0\u4f9b\u4e86\u603b\u7ed3\u548c\u8fc1\u79fb\u6307\u5357\uff0c\u9002\u5408\u5f00\u53d1\u8005\u53c2\u8003\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u533a\u5206Python2\u548cPython3\u7684\u5173\u952e\u70b9\u5305\u62ec\uff1a\u8bed\u6cd5\u5dee\u5f02\u3001\u5e93\u652f\u6301\u3001\u5b57\u7b26\u4e32\u5904\u7406\u3001\u6574\u6570\u9664\u6cd5\u3001\u8f93\u5165\u8f93\u51fa\u51fd\u6570\u3001Unic [&hellip;]","protected":false},"author":3,"featured_media":948779,"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\/948770"}],"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=948770"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/948770\/revisions"}],"predecessor-version":[{"id":948781,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/948770\/revisions\/948781"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/948779"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=948770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=948770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=948770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}