{"id":1164675,"date":"2025-01-15T15:10:35","date_gmt":"2025-01-15T07:10:35","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1164675.html"},"modified":"2025-01-15T15:10:37","modified_gmt":"2025-01-15T07:10:37","slug":"python%e5%a4%8d%e5%88%b6%e4%bb%a3%e7%a0%81%e5%90%8e%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1164675.html","title":{"rendered":"python\u590d\u5236\u4ee3\u7801\u540e\u5982\u4f55\u8fd0\u884c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25205148\/8f440aa2-4e48-41e2-a77b-1fa91dbf0b7d.webp\" alt=\"python\u590d\u5236\u4ee3\u7801\u540e\u5982\u4f55\u8fd0\u884c\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u8fd0\u884c\u590d\u5236\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\u3001\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u811a\u672c\u6587\u4ef6\u4e2d\u5e76\u8fd0\u884c\u8be5\u6587\u4ef6\u3001\u4f7f\u7528IDE\u6216\u4ee3\u7801\u7f16\u8f91\u5668\u8fd0\u884c\u4ee3\u7801\u3002<\/strong>\u5176\u4e2d\uff0c\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u811a\u672c\u6587\u4ef6\u4e2d\u5e76\u8fd0\u884c\u8be5\u6587\u4ef6\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d<\/h3>\n<\/p>\n<p><p>Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u662f\u4e00\u4e2a\u65b9\u4fbf\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u754c\u9762\u4e2d\u8f93\u5165\u548c\u6267\u884cPython\u4ee3\u7801\u3002\u8981\u5728\u89e3\u91ca\u5668\u4e2d\u8fd0\u884c\u590d\u5236\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\uff08Windows\u4e0a\u662fcmd\uff0cMac\u548cLinux\u4e0a\u662f\u7ec8\u7aef\uff09\u3002<\/li>\n<li>\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u5e76\u6309\u56de\u8f66\u952e\u8fdb\u5165Python\u89e3\u91ca\u5668\u3002<\/li>\n<li>\u5c06\u590d\u5236\u7684\u4ee3\u7801\u7c98\u8d34\u5230\u89e3\u91ca\u5668\u4e2d\u3002<\/li>\n<li>\u6309\u56de\u8f66\u952e\u6267\u884c\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u4e8e\u8fd0\u884c\u5c11\u91cf\u7684\u4ee3\u7801\u7247\u6bb5\u6216\u8fdb\u884c\u7b80\u5355\u7684\u6d4b\u8bd5\uff0c\u4f46\u5bf9\u4e8e\u8f83\u957f\u7684\u4ee3\u7801\u6216\u590d\u6742\u7684\u9879\u76ee\uff0c\u5efa\u8bae\u4f7f\u7528\u811a\u672c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u811a\u672c\u6587\u4ef6\u4e2d\u5e76\u8fd0\u884c\u8be5\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5c06\u590d\u5236\u7684\u4ee3\u7801\u7c98\u8d34\u5230\u4e00\u4e2aPython\u811a\u672c\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u8fd0\u884c\u8be5\u6587\u4ef6\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u4e00\u4e2a\u4ee3\u7801\u7f16\u8f91\u5668\uff08\u5982VSCode\u3001PyCharm\u3001Sublime Text\u7b49\uff09\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u6587\u4ef6\u4fdd\u5b58\u4e3a<code>.py<\/code>\u6269\u5c55\u540d\uff0c\u4f8b\u5982<code>example.py<\/code>\u3002<\/li>\n<li>\u5c06\u590d\u5236\u7684\u4ee3\u7801\u7c98\u8d34\u5230\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u3002<\/li>\n<li>\u4fdd\u5b58\u6587\u4ef6\u3002<\/li>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\uff0c\u5bfc\u822a\u5230\u4fdd\u5b58\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/li>\n<li>\u8f93\u5165<code>python example.py<\/code>\u6216<code>python3 example.py<\/code>\u5e76\u6309\u56de\u8f66\u952e\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u8fd0\u884c\u8f83\u957f\u7684\u4ee3\u7801\u548c\u5f00\u53d1\u590d\u6742\u7684\u9879\u76ee\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528IDE\u6216\u4ee3\u7801\u7f16\u8f91\u5668\u8fd0\u884c\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u73b0\u4ee3\u7684IDE\uff08\u5982PyCharm\uff09\u548c\u4ee3\u7801\u7f16\u8f91\u5668\uff08\u5982VSCode\uff09\u63d0\u4f9b\u4e86\u76f4\u63a5\u8fd0\u884c\u4ee3\u7801\u7684\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u8fd9\u4e9b\u5de5\u5177\u8fd0\u884c\u4ee3\u7801\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00IDE\u6216\u4ee3\u7801\u7f16\u8f91\u5668\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\uff0c\u5e76\u5c06\u6587\u4ef6\u4fdd\u5b58\u4e3a<code>.py<\/code>\u6269\u5c55\u540d\u3002<\/li>\n<li>\u5c06\u590d\u5236\u7684\u4ee3\u7801\u7c98\u8d34\u5230\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u3002<\/li>\n<li>\u4fdd\u5b58\u6587\u4ef6\u3002<\/li>\n<li>\u5728IDE\u6216\u7f16\u8f91\u5668\u4e2d\u627e\u5230\u8fd0\u884c\u6309\u94ae\uff0c\u901a\u5e38\u662f\u4e00\u4e2a\u7eff\u8272\u7684\u4e09\u89d2\u5f62\u56fe\u6807\uff0c\u70b9\u51fb\u5b83\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u76f4\u89c2\u4e14\u65b9\u4fbf\uff0c\u9002\u5408\u4e8e\u5f00\u53d1\u548c\u8c03\u8bd5\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u8be6\u7ec6\u63cf\u8ff0\uff1a\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u811a\u672c\u6587\u4ef6\u4e2d\u5e76\u8fd0\u884c\u8be5\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u811a\u672c\u6587\u4ef6\u4e2d\u5e76\u8fd0\u884c\u8be5\u6587\u4ef6\u662f\u6700\u5e38\u89c1\u548c\u63a8\u8350\u7684\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\u548c\u4e00\u4e9b\u989d\u5916\u7684\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684\u4ee3\u7801\u7f16\u8f91\u5668<\/strong>\uff1a\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u662f\u5173\u952e\u3002\u63a8\u8350\u4f7f\u7528VSCode\u3001PyCharm\u6216Sublime Text\u7b49\uff0c\u8fd9\u4e9b\u7f16\u8f91\u5668\u90fd\u652f\u6301Python\u8bed\u6cd5\u9ad8\u4eae\u3001\u81ea\u52a8\u8865\u5168\u548c\u8c03\u8bd5\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u65b0\u7684Python\u6587\u4ef6<\/strong>\uff1a\u5728\u4ee3\u7801\u7f16\u8f91\u5668\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u5e76\u4fdd\u5b58\u4e3a<code>.py<\/code>\u6269\u5c55\u540d\u3002\u4f8b\u5982\uff0c<code>example.py<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7c98\u8d34\u4ee3\u7801<\/strong>\uff1a\u5c06\u590d\u5236\u7684\u4ee3\u7801\u7c98\u8d34\u5230\u65b0\u521b\u5efa\u7684Python\u6587\u4ef6\u4e2d\u3002\u786e\u4fdd\u4ee3\u7801\u6ca1\u6709\u683c\u5f0f\u9519\u8bef\uff0c\u5c24\u5176\u662f\u7f29\u8fdb\u95ee\u9898\uff0c\u56e0\u4e3aPython\u5bf9\u7f29\u8fdb\u975e\u5e38\u654f\u611f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u5b58\u6587\u4ef6<\/strong>\uff1a\u4fdd\u5b58\u6587\u4ef6\u4ee5\u786e\u4fdd\u6240\u6709\u66f4\u6539\u90fd\u5df2\u5199\u5165\u78c1\u76d8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6253\u5f00\u547d\u4ee4\u884c<\/strong>\uff1a\u6253\u5f00\u547d\u4ee4\u884c\uff08cmd\u3001\u7ec8\u7aef\u6216PowerShell\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u822a\u5230\u6587\u4ef6\u76ee\u5f55<\/strong>\uff1a\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u4fdd\u5b58Python\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6587\u4ef6\u4fdd\u5b58\u5728<code>C:\\Users\\Username\\Documents<\/code>\uff0c\u5219\u8f93\u5165<code>cd C:\\Users\\Username\\Documents<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u6587\u4ef6<\/strong>\uff1a\u8f93\u5165<code>python example.py<\/code>\u6216<code>python3 example.py<\/code>\u5e76\u6309\u56de\u8f66\u952e\u8fd0\u884c\u4ee3\u7801\u3002\u5982\u679c\u4f60\u7684\u7cfb\u7edf\u4e0a\u5b89\u88c5\u4e86\u591a\u4e2aPython\u7248\u672c\uff0c\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684Python\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u8f93\u51fa\u548c\u9519\u8bef<\/strong>\uff1a\u8fd0\u884c\u4ee3\u7801\u540e\uff0c\u68c0\u67e5\u547d\u4ee4\u884c\u4e2d\u7684\u8f93\u51fa\u3002\u5982\u679c\u51fa\u73b0\u9519\u8bef\uff0c\u6839\u636e\u9519\u8bef\u6d88\u606f\u8fdb\u884c\u8c03\u8bd5\u548c\u4fee\u6b63\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u4fdd\u5b58\u548c\u91cd\u590d\u8fd0\u884c\u4ee3\u7801\uff0c\u9002\u5408\u4e8e\u5f00\u53d1\u548c\u8c03\u8bd5\u8f83\u5927\u7684\u9879\u76ee\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u4ee3\u7801\u7f16\u8f91\u5668\u53ef\u4ee5\u4eab\u53d7\u4ee3\u7801\u8865\u5168\u3001\u8bed\u6cd5\u68c0\u67e5\u548c\u8c03\u8bd5\u7b49\u529f\u80fd\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8fd0\u884cPython\u4ee3\u7801\u7684\u5176\u4ed6\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u51e0\u79cd\u5e38\u89c1\u65b9\u6cd5\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u8fd0\u884cPython\u4ee3\u7801\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528Jupyter Notebook<\/h4>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u8ba1\u7b97\u73af\u5883\uff0c\u9002\u5408\u4e8e\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u548c\u5b66\u672f\u7814\u7a76\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fd0\u884c\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5Jupyter Notebook\uff1a\u4f7f\u7528\u547d\u4ee4<code>pip install jupyter<\/code>\u5b89\u88c5\u3002<\/li>\n<li>\u542f\u52a8Jupyter Notebook\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>jupyter notebook<\/code>\u5e76\u6309\u56de\u8f66\u952e\u3002<\/li>\n<li>\u521b\u5efa\u65b0\u7684Notebook\uff1a\u5728Jupyter\u754c\u9762\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python Notebook\u3002<\/li>\n<li>\u7c98\u8d34\u4ee3\u7801\uff1a\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Notebook\u5355\u5143\u683c\u4e2d\u3002<\/li>\n<li>\u8fd0\u884c\u5355\u5143\u683c\uff1a\u6309Shift+Enter\u952e\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><h4>2\u3001\u4f7f\u7528\u5728\u7ebfPython\u89e3\u91ca\u5668<\/h4>\n<\/p>\n<p><p>\u5728\u7ebfPython\u89e3\u91ca\u5668\u662f\u4e00\u4e2a\u65b9\u4fbf\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884cPython\u4ee3\u7801\u3002\u5e38\u7528\u7684\u5728\u7ebf\u89e3\u91ca\u5668\u5305\u62ecRepl.it\u3001Google Colab\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u5728\u7ebfPython\u89e3\u91ca\u5668\u7f51\u7ad9\uff0c\u4f8b\u5982Repl.it\uff08<a href=\"https:\/\/repl.it\/~%EF%BC%89%E3%80%82\">https:\/\/repl.it\/~\uff09\u3002<\/a><\/li>\n<li>\u521b\u5efa\u65b0\u7684Python\u9879\u76ee\u3002<\/li>\n<li>\u5c06\u4ee3\u7801\u7c98\u8d34\u5230\u7f16\u8f91\u5668\u4e2d\u3002<\/li>\n<li>\u70b9\u51fb\u8fd0\u884c\u6309\u94ae\u6267\u884c\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><h4>3\u3001\u4f7f\u7528Python\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u5927\u578b\u9879\u76ee\u65f6\uff0c\u4f7f\u7528Python\u865a\u62df\u73af\u5883\u53ef\u4ee5\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\uff0c\u907f\u514d\u4f9d\u8d56\u51b2\u7a81\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u865a\u62df\u73af\u5883\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c<code>python -m venv venv<\/code>\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/li>\n<li>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a\u5728Windows\u4e0a\u8fd0\u884c<code>venv\\Scripts\\activate<\/code>\uff0c\u5728Mac\u548cLinux\u4e0a\u8fd0\u884c<code>source venv\/bin\/activate<\/code>\u3002<\/li>\n<li>\u5b89\u88c5\u4f9d\u8d56\uff1a\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fd0\u884c<code>pip install<\/code>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56\u3002<\/li>\n<li>\u8fd0\u884c\u4ee3\u7801\uff1a\u5728\u865a\u62df\u73af\u5883\u4e2d\u8fd0\u884c<code>python example.py<\/code>\u3002<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u865a\u62df\u73af\u5883\u53ef\u4ee5\u786e\u4fdd\u9879\u76ee\u4f9d\u8d56\u7684\u72ec\u7acb\u6027\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u8c03\u8bd5\u548c\u4f18\u5316Python\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u8fd0\u884cPython\u4ee3\u7801\u540e\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u548c\u6027\u80fd\u95ee\u9898\u3002\u8c03\u8bd5\u548c\u4f18\u5316\u4ee3\u7801\u662f\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u8c03\u8bd5\u548c\u4f18\u5316\u7684\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528\u8c03\u8bd5\u5668<\/h4>\n<\/p>\n<p><p>\u8c03\u8bd5\u5668\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u9010\u884c\u6267\u884c\u4ee3\u7801\uff0c\u68c0\u67e5\u53d8\u91cf\u503c\u548c\u7a0b\u5e8f\u72b6\u6001\u3002\u5e38\u7528\u7684\u8c03\u8bd5\u5668\u5305\u62ecPDB\uff08Python\u8c03\u8bd5\u5668\uff09\u548cIDE\u5185\u7f6e\u8c03\u8bd5\u5668\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528PDB\uff1a\u5728\u4ee3\u7801\u4e2d\u63d2\u5165<code>import pdb; pdb.set_trace()<\/code>\uff0c\u8fd0\u884c\u4ee3\u7801\u540e\u7a0b\u5e8f\u4f1a\u5728\u8be5\u884c\u6682\u505c\uff0c\u53ef\u4ee5\u9010\u884c\u6267\u884c\u4ee3\u7801\u3002<\/li>\n<li>\u4f7f\u7528IDE\u8c03\u8bd5\u5668\uff1a\u5728IDE\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u542f\u52a8\u8c03\u8bd5\u6a21\u5f0f\uff0c\u53ef\u4ee5\u9010\u884c\u6267\u884c\u4ee3\u7801\u548c\u68c0\u67e5\u53d8\u91cf\u3002<\/li>\n<\/ol>\n<p><h4>2\u3001\u68c0\u67e5\u9519\u8bef\u6d88\u606f<\/h4>\n<\/p>\n<p><p>\u9519\u8bef\u6d88\u606f\u901a\u5e38\u5305\u542b\u9519\u8bef\u7c7b\u578b\u3001\u9519\u8bef\u4f4d\u7f6e\u548c\u9519\u8bef\u63cf\u8ff0\u3002\u6839\u636e\u9519\u8bef\u6d88\u606f\uff0c\u53ef\u4ee5\u5feb\u901f\u5b9a\u4f4d\u548c\u4fee\u6b63\u9519\u8bef\u3002\u4f8b\u5982\uff0c<code>SyntaxError<\/code>\u8868\u793a\u8bed\u6cd5\u9519\u8bef\uff0c<code>IndexError<\/code>\u8868\u793a\u7d22\u5f15\u8d85\u51fa\u8303\u56f4\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u4f18\u5316\u4ee3\u7801\u6027\u80fd<\/h4>\n<\/p>\n<p><p>\u6027\u80fd\u4f18\u5316\u662f\u63d0\u9ad8\u4ee3\u7801\u6548\u7387\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u4f18\u5316\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u7b97\u6cd5\u4f18\u5316<\/strong>\uff1a\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u6548\u7387\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u54c8\u5e0c\u8868\u4ee3\u66ff\u5217\u8868\u53ef\u4ee5\u63d0\u9ad8\u67e5\u627e\u901f\u5ea6\u3002<\/li>\n<li><strong>\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97<\/strong>\uff1a\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u548c\u4e0d\u5fc5\u8981\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u5c06\u5faa\u73af\u4e2d\u7684\u5e38\u91cf\u8ba1\u7b97\u79fb\u5230\u5faa\u73af\u5916\u3002<\/li>\n<li><strong>\u4f7f\u7528\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b<\/strong>\uff1a\u5728I\/O\u5bc6\u96c6\u578b\u4efb\u52a1\u4e2d\uff0c\u4f7f\u7528\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd\u3002<\/li>\n<li><strong>\u4f7f\u7528\u7f13\u5b58<\/strong>\uff1a\u5bf9\u4e8e\u91cd\u590d\u8ba1\u7b97\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u7f13\u5b58\u63d0\u9ad8\u6548\u7387\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>functools.lru_cache<\/code>\u88c5\u9970\u5668\u7f13\u5b58\u51fd\u6570\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u5b66\u4e60\u548c\u63d0\u9ad8Python\u7f16\u7a0b\u6280\u80fd<\/h3>\n<\/p>\n<p><p>\u5b66\u4e60\u548c\u63d0\u9ad8Python\u7f16\u7a0b\u6280\u80fd\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8bae\u548c\u8d44\u6e90\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u9605\u8bfb\u5b98\u65b9\u6587\u6863<\/h4>\n<\/p>\n<p><p>Python\u5b98\u65b9\u6587\u6863\uff08<a href=\"https:\/\/docs.python.org\/3\/%EF%BC%89%E6%98%AF%E6%9C%80%E6%9D%83%E5%A8%81%E7%9A%84%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99%EF%BC%8C%E5%8C%85%E5%90%ABPython%E8%AF%AD%E8%A8%80%E7%9A%84%E8%AF%A6%E7%BB%86%E4%BB%8B%E7%BB%8D%E3%80%81%E6%A0%87%E5%87%86%E5%BA%93%E5%92%8C%E5%B8%B8%E7%94%A8%E6%A8%A1%E5%9D%97%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E3%80%82\">https:\/\/docs.python.org\/3\/\uff09\u662f\u6700\u6743\u5a01\u7684\u53c2\u8003\u8d44\u6599\uff0c\u5305\u542bPython\u8bed\u8a00\u7684\u8be6\u7ec6\u4ecb\u7ecd\u3001\u6807\u51c6\u5e93\u548c\u5e38\u7528\u6a21\u5757\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/a><\/p>\n<\/p>\n<p><h4>2\u3001\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee<\/h4>\n<\/p>\n<p><p>\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u662f\u63d0\u9ad8\u7f16\u7a0b\u6280\u80fd\u7684\u597d\u65b9\u6cd5\u3002\u53ef\u4ee5\u5728GitHub\uff08<a href=\"https:\/\/github.com\/%EF%BC%89%E4%B8%8A%E6%89%BE%E5%88%B0%E6%84%9F%E5%85%B4%E8%B6%A3%E7%9A%84%E9%A1%B9%E7%9B%AE%EF%BC%8C%E9%98%85%E8%AF%BB%E4%BB%A3%E7%A0%81%E3%80%81%E6%8F%90%E4%BA%A4%E9%97%AE%E9%A2%98%E5%92%8C%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81%E3%80%82\">https:\/\/github.com\/\uff09\u4e0a\u627e\u5230\u611f\u5174\u8da3\u7684\u9879\u76ee\uff0c\u9605\u8bfb\u4ee3\u7801\u3001\u63d0\u4ea4\u95ee\u9898\u548c\u8d21\u732e\u4ee3\u7801\u3002<\/a><\/p>\n<\/p>\n<p><h4>3\u3001\u5b66\u4e60\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784<\/h4>\n<\/p>\n<p><p>\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u662f\u7f16\u7a0b\u7684\u57fa\u7840\u3002\u53ef\u4ee5\u901a\u8fc7\u5b66\u4e60\u7ecf\u5178\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\uff0c\u63d0\u9ad8\u89e3\u51b3\u95ee\u9898\u7684\u80fd\u529b\u3002\u63a8\u8350\u300a\u7b97\u6cd5\u5bfc\u8bba\u300b\u548c\u300a\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5206\u6790\u300b\u7b49\u4e66\u7c4d\u3002<\/p>\n<\/p>\n<p><h4>4\u3001\u53c2\u52a0\u7f16\u7a0b\u6bd4\u8d5b<\/h4>\n<\/p>\n<p><p>\u7f16\u7a0b\u6bd4\u8d5b\u662f\u953b\u70bc\u7f16\u7a0b\u80fd\u529b\u548c\u63d0\u9ad8\u7b97\u6cd5\u6c34\u5e73\u7684\u597d\u65b9\u6cd5\u3002\u5e38\u89c1\u7684\u7f16\u7a0b\u6bd4\u8d5b\u5e73\u53f0\u5305\u62ecLeetCode\uff08<a href=\"https:\/\/leetcode.com\/%EF%BC%89%E3%80%81Codeforces%EF%BC%88https:\/\/codeforces.com\/%EF%BC%89%E7%AD%89%E3%80%82\">https:\/\/leetcode.com\/\uff09\u3001Codeforces\uff08https:\/\/codeforces.com\/\uff09\u7b49\u3002<\/a><\/p>\n<\/p>\n<p><h4>5\u3001\u6301\u7eed\u7f16\u5199\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u7f16\u5199\u4ee3\u7801\u662f\u63d0\u9ad8\u7f16\u7a0b\u6280\u80fd\u7684\u5173\u952e\u3002\u53ef\u4ee5\u901a\u8fc7\u5b8c\u6210\u5b9e\u9645\u9879\u76ee\u3001\u89e3\u51b3\u7f16\u7a0b\u95ee\u9898\u548c\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\uff0c\u4e0d\u65ad\u79ef\u7d2f\u7ecf\u9a8c\u548c\u63d0\u9ad8\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001Python\u4ee3\u7801\u7684\u5e38\u89c1\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u8fd0\u884cPython\u4ee3\u7801\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u8bed\u6cd5\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u8bed\u6cd5\u9519\u8bef\u662f\u6700\u5e38\u89c1\u7684\u95ee\u9898\u4e4b\u4e00\u3002\u901a\u5e38\u662f\u7531\u4e8e\u4ee3\u7801\u683c\u5f0f\u4e0d\u6b63\u786e\u3001\u62fc\u5199\u9519\u8bef\u6216\u4f7f\u7528\u4e86\u4e0d\u652f\u6301\u7684\u8bed\u6cd5\u3002<\/p>\n<\/p>\n<p><p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u68c0\u67e5\u4ee3\u7801\u683c\u5f0f\uff0c\u786e\u4fdd\u7f29\u8fdb\u6b63\u786e\u3002<\/li>\n<li>\u68c0\u67e5\u62fc\u5199\u9519\u8bef\uff0c\u7279\u522b\u662f\u5173\u952e\u5b57\u548c\u53d8\u91cf\u540d\u3002<\/li>\n<li>\u4f7f\u7528Python\u89e3\u91ca\u5668\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\uff0c\u8fd0\u884c\u4ee3\u7801\u65f6\u4f1a\u663e\u793a\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p><h4>2\u3001\u6a21\u5757\u5bfc\u5165\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6a21\u5757\u672a\u627e\u5230\u6216\u5bfc\u5165\u5931\u8d25\u7684\u9519\u8bef\u3002\u901a\u5e38\u662f\u7531\u4e8e\u6a21\u5757\u672a\u5b89\u88c5\u6216\u5bfc\u5165\u8def\u5f84\u4e0d\u6b63\u786e\u3002<\/p>\n<\/p>\n<p><p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u6a21\u5757\u5df2\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install<\/code>\u547d\u4ee4\u5b89\u88c5\u6a21\u5757\u3002<\/li>\n<li>\u68c0\u67e5\u5bfc\u5165\u8def\u5f84\uff0c\u786e\u4fdd\u6a21\u5757\u5728\u6b63\u786e\u7684\u8def\u5f84\u4e0b\u3002<\/li>\n<li>\u4f7f\u7528\u865a\u62df\u73af\u5883\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\uff0c\u907f\u514d\u4f9d\u8d56\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<p><h4>3\u3001\u53d8\u91cf\u672a\u5b9a\u4e49<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u672a\u5b9a\u4e49\u7684\u53d8\u91cf\u4f1a\u5bfc\u81f4\u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u901a\u5e38\u662f\u7531\u4e8e\u53d8\u91cf\u672a\u8d4b\u503c\u6216\u62fc\u5199\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u53d8\u91cf\u5728\u4f7f\u7528\u524d\u5df2\u8d4b\u503c\u3002<\/li>\n<li>\u68c0\u67e5\u62fc\u5199\u9519\u8bef\uff0c\u7279\u522b\u662f\u53d8\u91cf\u540d\u3002<\/li>\n<li>\u4f7f\u7528IDE\u6216\u4ee3\u7801\u7f16\u8f91\u5668\u7684\u81ea\u52a8\u8865\u5168\u529f\u80fd\uff0c\u51cf\u5c11\u62fc\u5199\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><h4>4\u3001\u7d22\u5f15\u8d85\u51fa\u8303\u56f4<\/h4>\n<\/p>\n<p><p>\u8bbf\u95ee\u5217\u8868\u6216\u5b57\u7b26\u4e32\u65f6\uff0c\u7d22\u5f15\u8d85\u51fa\u8303\u56f4\u4f1a\u5bfc\u81f4\u8fd0\u884c\u65f6\u9519\u8bef\u3002\u901a\u5e38\u662f\u7531\u4e8e\u5faa\u73af\u6761\u4ef6\u4e0d\u6b63\u786e\u6216\u8bbf\u95ee\u4e86\u4e0d\u5b58\u5728\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u68c0\u67e5\u5faa\u73af\u6761\u4ef6\uff0c\u786e\u4fdd\u7d22\u5f15\u5728\u6709\u6548\u8303\u56f4\u5185\u3002<\/li>\n<li>\u4f7f\u7528<code>len()<\/code>\u51fd\u6570\u68c0\u67e5\u5217\u8868\u6216\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002<\/li>\n<li>\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u6355\u83b7\u7d22\u5f15\u9519\u8bef\uff0c\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u3002<\/li>\n<\/ul>\n<p><h4>5\u3001\u7c7b\u578b\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u7c7b\u578b\u9519\u8bef\u662f\u7531\u4e8e\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u8fdb\u884c\u4e0d\u652f\u6301\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u5c06\u5b57\u7b26\u4e32\u548c\u6574\u6570\u76f8\u52a0\u3002<\/p>\n<\/p>\n<p><p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u68c0\u67e5\u53d8\u91cf\u7c7b\u578b\uff0c\u786e\u4fdd\u64cd\u4f5c\u7684\u53d8\u91cf\u7c7b\u578b\u517c\u5bb9\u3002<\/li>\n<li>\u4f7f\u7528\u7c7b\u578b\u8f6c\u6362\u51fd\u6570\uff0c\u5982<code>int()<\/code>\u3001<code>str()<\/code>\u7b49\u3002<\/li>\n<li>\u4f7f\u7528IDE\u6216\u4ee3\u7801\u7f16\u8f91\u5668\u7684\u7c7b\u578b\u68c0\u67e5\u529f\u80fd\uff0c\u51cf\u5c11\u7c7b\u578b\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><h3>\u516b\u3001Python\u4ee3\u7801\u7684\u8c03\u8bd5\u6280\u5de7<\/h3>\n<\/p>\n<p><p>\u8c03\u8bd5\u662f\u4fee\u6b63\u4ee3\u7801\u9519\u8bef\u548c\u4f18\u5316\u4ee3\u7801\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u8c03\u8bd5\u6280\u5de7\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528print\u8bed\u53e5<\/h4>\n<\/p>\n<p><p><code>print<\/code>\u8bed\u53e5\u662f\u6700\u7b80\u5355\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u53ef\u4ee5\u8f93\u51fa\u53d8\u91cf\u503c\u548c\u7a0b\u5e8f\u72b6\u6001\uff0c\u5e2e\u52a9\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 10<\/p>\n<p>print(f&#39;x = {x}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u65ad\u70b9<\/h4>\n<\/p>\n<p><p>\u65ad\u70b9\u662f\u8c03\u8bd5\u5668\u4e2d\u7684\u91cd\u8981\u5de5\u5177\uff0c\u53ef\u4ee5\u6682\u505c\u7a0b\u5e8f\u6267\u884c\uff0c\u68c0\u67e5\u53d8\u91cf\u503c\u548c\u7a0b\u5e8f\u72b6\u6001\u3002\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u63d2\u5165\u65ad\u70b9\uff0c\u9010\u884c\u6267\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb<\/p>\n<p>pdb.set_trace()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528\u65e5\u5fd7<\/h4>\n<\/p>\n<p><p>\u65e5\u5fd7\u662f\u8bb0\u5f55\u7a0b\u5e8f\u8fd0\u884c\u72b6\u6001\u548c\u9519\u8bef\u4fe1\u606f\u7684\u91cd\u8981\u5de5\u5177\u3002\u53ef\u4ee5\u4f7f\u7528<code>logging<\/code>\u6a21\u5757\u8bb0\u5f55\u65e5\u5fd7\uff0c\u4fbf\u4e8e\u8c03\u8bd5\u548c\u5206\u6790\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import logging<\/p>\n<p>logging.basicConfig(level=logging.DEBUG)<\/p>\n<p>logging.debug(&#39;This is a debug message&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u4f7f\u7528\u5355\u5143\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>\u5355\u5143\u6d4b\u8bd5\u662f\u9a8c\u8bc1\u4ee3\u7801\u6b63\u786e\u6027\u7684\u91cd\u8981\u65b9\u6cd5\u3002\u53ef\u4ee5\u4f7f\u7528<code>unittest<\/code>\u6a21\u5757\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4ee3\u7801\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>class TestExample(unittest.TestCase):<\/p>\n<p>    def test_add(self):<\/p>\n<p>        self.assertEqual(1 + 1, 2)<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001Python\u4ee3\u7801\u7684\u4f18\u5316\u7b56\u7565<\/h3>\n<\/p>\n<p><p>\u4f18\u5316\u4ee3\u7801\u6027\u80fd\u662f\u63d0\u9ad8\u7a0b\u5e8f\u6548\u7387\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u4f18\u5316\u7b56\u7565\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u7b97\u6cd5\u4f18\u5316<\/h4>\n<\/p>\n<p><p>\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u54c8\u5e0c\u8868\u4ee3\u66ff\u5217\u8868\u63d0\u9ad8\u67e5\u627e\u901f\u5ea6\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5217\u8868\u67e5\u627e<\/p>\n<p>items = [1, 2, 3, 4, 5]<\/p>\n<p>if 3 in items:<\/p>\n<p>    print(&#39;Found&#39;)<\/p>\n<h2><strong>\u4f7f\u7528\u54c8\u5e0c\u8868\u67e5\u627e<\/strong><\/h2>\n<p>items = {1, 2, 3, 4, 5}<\/p>\n<p>if 3 in items:<\/p>\n<p>    print(&#39;Found&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u548c\u4e0d\u5fc5\u8981\u7684\u64cd\u4f5c\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u6548\u7387\u3002\u4f8b\u5982\uff0c\u5c06\u5faa\u73af\u4e2d\u7684\u5e38\u91cf\u8ba1\u7b97\u79fb\u5230\u5faa\u73af\u5916\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97<\/p>\n<p>for i in range(100):<\/p>\n<p>    result = i * 3.14<\/p>\n<h2><strong>\u4f18\u5316\u540e<\/strong><\/h2>\n<p>pi = 3.14<\/p>\n<p>for i in range(100):<\/p>\n<p>    result = i * pi<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b<\/h4>\n<\/p>\n<p><p>\u5728I\/O\u5bc6\u96c6\u578b\u4efb\u52a1\u4e2d\uff0c\u4f7f\u7528\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u4e0b\u8f7d\u6587\u4ef6\u6216\u5904\u7406\u7f51\u7edc\u8bf7\u6c42\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>def download_file(url):<\/p>\n<p>    # \u4e0b\u8f7d\u6587\u4ef6\u4ee3\u7801<\/p>\n<p>    pass<\/p>\n<p>urls = [&#39;url1&#39;, &#39;url2&#39;, &#39;url3&#39;]<\/p>\n<p>threads = []<\/p>\n<p>for url in urls:<\/p>\n<p>    thread = threading.Thread(target=download_file, args=(url,))<\/p>\n<p>    threads.append(thread)<\/p>\n<p>    thread.start()<\/p>\n<p>for thread in threads:<\/p>\n<p>    thread.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u4f7f\u7528\u7f13\u5b58<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u91cd\u590d\u8ba1\u7b97\u7684\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u7f13\u5b58\u63d0\u9ad8\u6548\u7387\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>functools.lru_cache<\/code>\u88c5\u9970\u5668\u7f13\u5b58\u51fd\u6570\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import functools<\/p>\n<p>@functools.lru_cache(maxsize=128)<\/p>\n<p>def fibonacci(n):<\/p>\n<p>    if n == 0:<\/p>\n<p>        return 0<\/p>\n<p>    elif n == 1:<\/p>\n<p>        return 1<\/p>\n<p>    else:<\/p>\n<p>        return fibonacci(n-1) + fibonacci(n-2)<\/p>\n<p>print(fibonacci(10))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001Python\u4ee3\u7801\u7684\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u9075\u5faa\u6700\u4f73\u5b9e\u8df5\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u9075\u5faaPEP 8<\/h4>\n<\/p>\n<p><p>PEP 8\u662fPython\u7684\u4ee3\u7801\u98ce\u683c\u6307\u5357\uff0c\u89c4\u5b9a\u4e86\u4ee3\u7801\u683c\u5f0f\u3001\u547d\u540d\u89c4\u8303\u7b49\u3002\u9075\u5faaPEP 8\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># PEP 8\u89c4\u8303\u7684\u4ee3\u7801<\/p>\n<p>def calculate_area(radius):<\/p>\n<p>    pi = 3.14<\/p>\n<p>    return pi * radius  2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7f16\u5199\u6587\u6863<\/h4>\n<\/p>\n<p><p>\u7f16\u5199\u6587\u6863\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u8bfb\u6027\u3002\u53ef\u4ee5\u4f7f\u7528\u6ce8\u91ca\u3001docstring\u548cREADME\u6587\u4ef6\u7f16\u5199\u6587\u6863\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_area(radius):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u8ba1\u7b97\u5706\u7684\u9762\u79ef<\/p>\n<p>    \u53c2\u6570:<\/p>\n<p>    radius (float): \u534a\u5f84<\/p>\n<p>    \u8fd4\u56de:<\/p>\n<p>    float: \u9762\u79ef<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    pi = 3.14<\/p>\n<p>    return pi * radius  2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u7f16\u5199\u5355\u5143\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>\u5355\u5143\u6d4b\u8bd5\u662f\u9a8c\u8bc1\u4ee3\u7801\u6b63\u786e\u6027\u7684\u91cd\u8981\u65b9\u6cd5\u3002\u53ef\u4ee5\u4f7f\u7528<code>unittest<\/code>\u6a21\u5757\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4ee3\u7801\u6b63\u786e\u6027\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>class TestExample(unittest.TestCase):<\/p>\n<p>    def test_add(self):<\/p>\n<p>        self.assertEqual(1 + 1, 2)<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u4f7f\u7528\u7248\u672c\u63a7\u5236<\/h4>\n<\/p>\n<p><p>\u7248\u672c\u63a7\u5236\u662f\u7ba1\u7406\u4ee3\u7801\u53d8\u66f4\u7684\u91cd\u8981\u5de5\u5177\u3002\u53ef\u4ee5\u4f7f\u7528Git\u7ba1\u7406\u4ee3\u7801\u7248\u672c\uff0c\u4fbf\u4e8e\u534f\u4f5c\u5f00\u53d1\u548c\u4ee3\u7801\u56de\u6eda\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u521d\u59cb\u5316Git\u4ed3\u5e93<\/p>\n<p>git init<\/p>\n<h2><strong>\u6dfb\u52a0\u6587\u4ef6\u5230\u6682\u5b58\u533a<\/strong><\/h2>\n<p>git add .<\/p>\n<h2><strong>\u63d0\u4ea4\u4ee3\u7801<\/strong><\/h2>\n<p>git commit -m &quot;Initial commit&quot;<\/p>\n<h2><strong>\u63a8\u9001\u4ee3\u7801\u5230\u8fdc\u7a0b\u4ed3\u5e93<\/strong><\/h2>\n<p>git remote add origin &lt;remote-repository-url&gt;<\/p>\n<p>git push -u origin master<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5\u3001\u9075\u5faaSOLID\u539f\u5219<\/h4>\n<\/p>\n<p><p>SOLID\u539f\u5219\u662f\u9762\u5411\u5bf9\u8c61\u8bbe\u8ba1\u7684\u4e94\u5927\u539f\u5219\uff0c\u5305\u62ec\u5355\u4e00\u804c\u8d23\u539f\u5219\u3001\u5f00\u653e\u5c01\u95ed\u539f\u5219\u3001\u91cc\u6c0f\u66ff\u6362\u539f\u5219\u3001\u63a5\u53e3\u9694\u79bb\u539f\u5219\u548c\u4f9d\u8d56\u5012\u7f6e\u539f\u5219\u3002\u9075\u5faaSOLID\u539f\u5219\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5355\u4e00\u804c\u8d23\u539f\u5219<\/p>\n<p>class Rectangle:<\/p>\n<p>    def __init__(self, width, height):<\/p>\n<p>        self.width = width<\/p>\n<p>        self.height = height<\/p>\n<p>    def calculate_area(self):<\/p>\n<p>        return self.width * self.height<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u590d\u5236\u548c\u7c98\u8d34\u4ee3\u7801\uff1f<\/strong><br \/>\u5728Python\u4e2d\u590d\u5236\u548c\u7c98\u8d34\u4ee3\u7801\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u9f20\u6807\u9009\u4e2d\u4ee3\u7801\uff0c\u53f3\u952e\u70b9\u51fb\u9009\u62e9\u201c\u590d\u5236\u201d\uff0c\u7136\u540e\u5728\u60a8\u5e0c\u671b\u8fd0\u884c\u4ee3\u7801\u7684\u5730\u65b9\u53f3\u952e\u70b9\u51fb\u5e76\u9009\u62e9\u201c\u7c98\u8d34\u201d\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u547d\u4ee4\u884c\u6216\u6587\u672c\u7f16\u8f91\u5668\uff0c\u901a\u5e38\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5feb\u6377\u952eCtrl+C\uff08\u590d\u5236\uff09\u548cCtrl+V\uff08\u7c98\u8d34\uff09\u6765\u5b8c\u6210\u8fd9\u4e00\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5728\u4ec0\u4e48\u73af\u5883\u4e0b\u6211\u53ef\u4ee5\u8fd0\u884c\u590d\u5236\u7684Python\u4ee3\u7801\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u5728\u591a\u79cd\u73af\u5883\u4e2d\u8fd0\u884cPython\u4ee3\u7801\uff0c\u5305\u62ec\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5982PyCharm\u3001Jupyter Notebook\u4ee5\u53ca\u5728\u7ebf\u4ee3\u7801\u7f16\u8f91\u5668\u5982Replit\u6216Google Colab\u3002\u8fd9\u4e9b\u5e73\u53f0\u4e3a\u60a8\u63d0\u4f9b\u4e86\u8fd0\u884cPython\u4ee3\u7801\u7684\u4fbf\u5229\uff0c\u60a8\u53ea\u9700\u7c98\u8d34\u4ee3\u7801\u5e76\u70b9\u51fb\u8fd0\u884c\u5373\u53ef\u3002<\/p>\n<p><strong>\u5982\u679c\u590d\u5236\u7684Python\u4ee3\u7801\u6709\u9519\u8bef\uff0c\u5982\u4f55\u8c03\u8bd5\uff1f<\/strong><br \/>\u8c03\u8bd5\u590d\u5236\u7684Python\u4ee3\u7801\u65f6\uff0c\u60a8\u53ef\u4ee5\u67e5\u770b\u9519\u8bef\u6d88\u606f\uff0c\u901a\u5e38\u4f1a\u6307\u793a\u9519\u8bef\u7684\u884c\u53f7\u548c\u7c7b\u578b\u3002\u786e\u4fdd\u4ee3\u7801\u683c\u5f0f\u6b63\u786e\uff0c\u6bd4\u5982\u7f29\u8fdb\u662f\u5426\u4e00\u81f4\uff0c\u53d8\u91cf\u662f\u5426\u5b9a\u4e49\u3002\u60a8\u4e5f\u53ef\u4ee5\u5728IDE\u4e2d\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\uff0c\u9010\u884c\u6267\u884c\u4ee3\u7801\uff0c\u68c0\u67e5\u53d8\u91cf\u503c\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3\u95ee\u9898\u6240\u5728\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u8fd0\u884c\u590d\u5236\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u5c06\u4ee3\u7801\u7c98\u8d34\u5230Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\u3001\u5c06\u4ee3\u7801\u7c98\u8d34\u5230P [&hellip;]","protected":false},"author":3,"featured_media":1164679,"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\/1164675"}],"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=1164675"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1164675\/revisions"}],"predecessor-version":[{"id":1164681,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1164675\/revisions\/1164681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1164679"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1164675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1164675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1164675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}