{"id":1178163,"date":"2025-01-15T18:07:20","date_gmt":"2025-01-15T10:07:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1178163.html"},"modified":"2025-01-15T18:07:23","modified_gmt":"2025-01-15T10:07:23","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bf%9b%e5%85%a5%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1178163.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u8fdb\u5165\u7a0b\u5e8f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25112908\/54fe45d7-364c-4570-b680-f667c9dae315.webp\" alt=\"python\u4e2d\u5982\u4f55\u8fdb\u5165\u7a0b\u5e8f\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u8fdb\u5165\u7a0b\u5e8f\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c<strong>\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u5728\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\u8f93\u5165\u4ee3\u7801\u3001\u4f7f\u7528Jupyter Notebook\u7b49<\/strong>\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\u3002<strong>\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c<\/strong>\u662f\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\u4e4b\u4e00\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u8fd0\u884c\u5df2\u7ecf\u7f16\u5199\u597d\u7684\u4ee3\u7801\u6587\u4ef6\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python script_name.py<\/code>\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884cPython\u811a\u672c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u79cd\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c<\/strong><\/p>\n<\/p>\n<ol>\n<li>\n<p>\u786e\u4fdd\u5df2\u5b89\u88c5Python\uff1a\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5728\u7cfb\u7edf\u4e0a\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\u786e\u8ba4\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u811a\u672c\uff1a\u4f7f\u7528\u4f60\u559c\u6b22\u7684\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982Notepad++\u3001Sublime Text\u3001Visual Studio Code\u7b49\uff09\u7f16\u5199Python\u811a\u672c\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a<code>.py<\/code>\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>hello.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">print(&quot;Hello, world!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\n<p>\u6253\u5f00\u547d\u4ee4\u884c\uff1a\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\u6216\u201cPowerShell\u201d\uff1b\u5728macOS\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u7ec8\u7aef\u201d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p>\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55\uff1a\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u4f60\u4fdd\u5b58Python\u811a\u672c\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u811a\u672c\u4fdd\u5b58\u5728<code>C:\\Users\\YourName\\Documents<\/code>\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u8f93\u5165\uff1a<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">cd C:\\Users\\YourName\\Documents<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"5\">\n<li>\u8fd0\u884cPython\u811a\u672c\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python hello.py<\/code>\u6216<code>python3 hello.py<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002\u4f60\u5e94\u8be5\u4f1a\u770b\u5230\u8f93\u51fa<code>Hello, world!<\/code>\u3002<\/li>\n<\/ol>\n<hr>\n<p><h2>\u4e00\u3001\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c<\/h2>\n<\/p>\n<p><h3>1\u3001\u786e\u4fdd\u5df2\u5b89\u88c5Python<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5728\u7cfb\u7edf\u4e0a\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\u786e\u8ba4\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/downloads\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E5%B9%B6%E5%AE%89%E8%A3%85%E9%80%82%E5%90%88%E4%BD%A0%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%89%88%E6%9C%AC%E3%80%82%E5%AE%89%E8%A3%85%E8%BF%87%E7%A8%8B%E4%B8%AD%EF%BC%8C%E5%BB%BA%E8%AE%AE%E5%8B%BE%E9%80%89%E2%80%9CAdd\">https:\/\/www.python.org\/downloads\/\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u5efa\u8bae\u52fe\u9009\u201cAdd<\/a> Python to PATH\u201d\u9009\u9879\uff0c\u4ee5\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528<code>python<\/code>\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u7f16\u5199Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u4f60\u559c\u6b22\u7684\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982Notepad++\u3001Sublime Text\u3001Visual Studio Code\u7b49\uff09\u7f16\u5199Python\u811a\u672c\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a<code>.py<\/code>\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>hello.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\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>\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u4efb\u610f\u65f6\u5019\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u6253\u5f00\u547d\u4ee4\u884c<\/h3>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u547d\u4ee4\u63d0\u793a\u7b26\u201d\u6216\u201cPowerShell\u201d\uff1b\u5728macOS\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u7ec8\u7aef\u201d\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u4f60\u4e0e\u7cfb\u7edf\u8fdb\u884c\u4ea4\u4e92\uff0c\u6267\u884c\u5404\u79cd\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><h3>4\u3001\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u76ee\u5f55<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<code>cd<\/code>\u547d\u4ee4\u5bfc\u822a\u5230\u4f60\u4fdd\u5b58Python\u811a\u672c\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u811a\u672c\u4fdd\u5b58\u5728<code>C:\\Users\\YourName\\Documents<\/code>\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd C:\\Users\\YourName\\Documents<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728macOS\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u5bfc\u822a\u5230\u76ee\u5f55\u7684\u547d\u4ee4\u4e0eWindows\u76f8\u540c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd \/Users\/YourName\/Documents<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u5f53\u524d\u76ee\u5f55\u662f\u4f60\u4fdd\u5b58\u811a\u672c\u7684\u76ee\u5f55\uff0c\u5426\u5219\u8fd0\u884c\u65f6\u4f1a\u63d0\u793a\u627e\u4e0d\u5230\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>5\u3001\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python hello.py<\/code>\u6216<code>python3 hello.py<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\u3002\u4f60\u5e94\u8be5\u4f1a\u770b\u5230\u8f93\u51fa<code>Hello, world!<\/code>\u3002\u5982\u679c\u811a\u672c\u4e2d\u6709\u5176\u4ed6\u4ee3\u7801\u6216\u903b\u8f91\uff0c\u4e5f\u4f1a\u6309\u987a\u5e8f\u6267\u884c\u5e76\u8f93\u51fa\u76f8\u5e94\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e8c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/h2>\n<\/p>\n<p><h3>1\u3001\u9009\u62e9\u9002\u5408\u7684IDE<\/h3>\n<\/p>\n<p><p>\u6709\u8bb8\u591a\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u53ef\u4f9b\u9009\u62e9\uff0c\u5982PyCharm\u3001Visual Studio Code\u3001Atom\u3001Jupyter Notebook\u7b49\u3002\u6bcf\u79cdIDE\u90fd\u6709\u5176\u72ec\u7279\u7684\u529f\u80fd\u548c\u7279\u70b9\uff0c\u53ef\u4ee5\u6839\u636e\u4e2a\u4eba\u9700\u6c42\u548c\u4e60\u60ef\u9009\u62e9\u9002\u5408\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u5b89\u88c5\u548c\u914d\u7f6eIDE<\/h3>\n<\/p>\n<p><p>\u4ee5PyCharm\u4e3a\u4f8b\uff0c\u9996\u5148\u4ecePyCharm\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.jetbrains.com\/pycharm\/download\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E5%B9%B6%E5%AE%89%E8%A3%85%E9%80%82%E5%90%88%E4%BD%A0%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E7%9A%84%E7%89%88%E6%9C%AC%E3%80%82%E5%AE%89%E8%A3%85%E5%AE%8C%E6%88%90%E5%90%8E%EF%BC%8C%E9%A6%96%E6%AC%A1%E5%90%AF%E5%8A%A8%E6%97%B6%E9%9C%80%E8%A6%81%E8%BF%9B%E8%A1%8C%E4%B8%80%E4%BA%9B%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE%EF%BC%8C%E5%A6%82%E9%80%89%E6%8B%A9%E4%B8%BB%E9%A2%98%E3%80%81%E9%85%8D%E7%BD%AEPython%E8%A7%A3%E9%87%8A%E5%99%A8%E7%AD%89%E3%80%82\">https:\/\/www.jetbr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns.com\/pycharm\/download\/\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u9002\u5408\u4f60\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u9996\u6b21\u542f\u52a8\u65f6\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u914d\u7f6e\uff0c\u5982\u9009\u62e9\u4e3b\u9898\u3001\u914d\u7f6ePython\u89e3\u91ca\u5668\u7b49\u3002<\/a><\/p>\n<\/p>\n<p><h3>3\u3001\u521b\u5efa\u9879\u76ee\u548cPython\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728PyCharm\u4e2d\uff0c\u70b9\u51fb\u201cFile\u201d-&gt;\u201cNew Project\u201d\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\uff0c\u9009\u62e9\u9879\u76ee\u4fdd\u5b58\u8def\u5f84\u548cPython\u89e3\u91ca\u5668\u3002\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u53f3\u952e\u70b9\u51fb\u201cNew\u201d-&gt;\u201cPython File\u201d\uff0c\u8f93\u5165\u6587\u4ef6\u540d\uff08\u5982<code>hello.py<\/code>\uff09\uff0c\u7136\u540e\u5728\u65b0\u5efa\u7684\u6587\u4ef6\u4e2d\u7f16\u5199Python\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, world!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728PyCharm\u4e2d\uff0c\u53f3\u952e\u70b9\u51fb\u811a\u672c\u6587\u4ef6\uff0c\u9009\u62e9\u201cRun &#39;hello&#39;\u201d\u5373\u53ef\u8fd0\u884c\u811a\u672c\u3002\u4f60\u53ef\u4ee5\u5728IDE\u7684\u8fd0\u884c\u7a97\u53e3\u4e2d\u770b\u5230\u8f93\u51fa\u7ed3\u679c<code>Hello, world!<\/code>\u3002\u6b64\u5916\uff0cPyCharm\u8fd8\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u8c03\u8bd5\u529f\u80fd\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u67e5\u770b\u53d8\u91cf\u503c\u3001\u9010\u6b65\u6267\u884c\u4ee3\u7801\u7b49\uff0c\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u8c03\u8bd5\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>5\u3001\u5176\u4ed6IDE\u7684\u4f7f\u7528<\/h3>\n<\/p>\n<p><p>\u9664\u4e86PyCharm\u5916\uff0c\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u4f18\u79c0\u7684IDE\u53ef\u4ee5\u9009\u62e9\u3002\u4f8b\u5982\uff0cVisual Studio Code\u662f\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u548c\u6269\u5c55\u3002\u4f60\u53ef\u4ee5\u4eceVisual Studio Code\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/code.visualstudio.com\/%EF%BC%89%E4%B8%8B%E8%BD%BD%E5%B9%B6%E5%AE%89%E8%A3%85%EF%BC%8C%E5%AE%89%E8%A3%85%E5%AE%8C%E6%88%90%E5%90%8E%E9%80%9A%E8%BF%87%E6%89%A9%E5%B1%95%E5%B8%82%E5%9C%BA%E5%AE%89%E8%A3%85Python%E6%8F%92%E4%BB%B6%EF%BC%8C%E5%8D%B3%E5%8F%AF%E8%BD%BB%E6%9D%BE%E7%BC%96%E5%86%99%E5%92%8C%E8%BF%90%E8%A1%8CPython%E4%BB%A3%E7%A0%81%E3%80%82\">https:\/\/code.visualstudio.com\/\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\uff0c\u5b89\u88c5\u5b8c\u6210\u540e\u901a\u8fc7\u6269\u5c55\u5e02\u573a\u5b89\u88c5Python\u63d2\u4ef6\uff0c\u5373\u53ef\u8f7b\u677e\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002<\/a><\/p>\n<\/p>\n<hr>\n<p><h2>\u4e09\u3001\u5728\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\u8f93\u5165\u4ee3\u7801<\/h2>\n<\/p>\n<p><h3>1\u3001\u6253\u5f00\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u6267\u884c\u3002\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\uff0c\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\uff0c\u5373\u53ef\u8fdb\u5165\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u73af\u5883\u3002\u4f60\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e8e<code>&gt;&gt;&gt;<\/code>\u7684\u63d0\u793a\u7b26\uff0c\u8868\u793a\u53ef\u4ee5\u8f93\u5165\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u8f93\u5165\u548c\u6267\u884cPython\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u5728\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u4e2d\uff0c\u53ef\u4ee5\u9010\u884c\u8f93\u5165Python\u4ee3\u7801\uff0c\u5e76\u7acb\u5373\u770b\u5230\u6267\u884c\u7ed3\u679c\u3002\u4f8b\u5982\uff0c\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u5e76\u6309\u4e0b\u56de\u8f66\u952e\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>\u4f60\u4f1a\u770b\u5230\u8f93\u51fa<code>Hello, world!<\/code>\u3002\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u975e\u5e38\u9002\u5408\u7528\u4e8e\u6d4b\u8bd5\u5c0f\u6bb5\u4ee3\u7801\u3001\u8c03\u8bd5\u548c\u5b66\u4e60Python\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u9000\u51fa\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>\u8981\u9000\u51fa\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u8f93\u5165<code>exit()<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\u952e\uff0c\u6216\u6309\u4e0b<code>Ctrl+D<\/code>\uff08\u5728macOS\u6216Linux\u7cfb\u7edf\u4e2d\uff09\u6216<code>Ctrl+Z<\/code>\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\uff08\u5728Windows\u7cfb\u7edf\u4e2d\uff09\u3002<\/p>\n<\/p>\n<p><h3>4\u3001\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u7684\u4f18\u52bf<\/h3>\n<\/p>\n<p><p>\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5373\u65f6\u53cd\u9988\u548c\u5feb\u901f\u6d4b\u8bd5\u3002\u4f60\u53ef\u4ee5\u5728\u7f16\u5199\u4ee3\u7801\u7684\u540c\u65f6\u7acb\u5373\u770b\u5230\u7ed3\u679c\uff0c\u5e2e\u52a9\u4f60\u5feb\u901f\u53d1\u73b0\u548c\u4fee\u590d\u9519\u8bef\u3002\u6b64\u5916\uff0c\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u8fd8\u652f\u6301\u8bb8\u591a\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u81ea\u52a8\u8865\u5168\u3001\u67e5\u770b\u6587\u6863\u7b49\uff0c\u63d0\u5347\u7f16\u7a0b\u6548\u7387\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u56db\u3001\u4f7f\u7528Jupyter Notebook<\/h2>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Jupyter Notebook<\/h3>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u6b3e\u5e7f\u53d7\u6b22\u8fce\u7684\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u5de5\u5177\uff0c\u7279\u522b\u9002\u5408\u7528\u4e8e\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7b49\u9886\u57df\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7<code>pip<\/code>\u547d\u4ee4\u5b89\u88c5Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>jupyter notebook<\/code>\u542f\u52a8Jupyter Notebook\u670d\u52a1\u5668\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u521b\u5efa\u548c\u8fd0\u884cNotebook<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>jupyter notebook<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\u952e\uff0c\u4f1a\u5728\u6d4f\u89c8\u5668\u4e2d\u81ea\u52a8\u6253\u5f00Jupyter Notebook\u4e3b\u9875\u3002\u5728\u4e3b\u9875\u4e2d\uff0c\u70b9\u51fb\u201cNew\u201d\u6309\u94ae\uff0c\u9009\u62e9\u201cPython 3\u201d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Notebook\u3002\u5728\u65b0\u5efa\u7684Notebook\u4e2d\uff0c\u53ef\u4ee5\u521b\u5efa\u548c\u8fd0\u884c\u591a\u4e2a\u4ee3\u7801\u5355\u5143\uff0c\u6bcf\u4e2a\u5355\u5143\u53ef\u4ee5\u5305\u542b\u4e00\u6bb5Python\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u7f16\u5199\u548c\u6267\u884c\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u5728Notebook\u7684\u4ee3\u7801\u5355\u5143\u4e2d\u8f93\u5165Python\u4ee3\u7801\uff0c\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<p><p>\u7136\u540e\u6309\u4e0b<code>Shift+Enter<\/code>\u952e\u5373\u53ef\u6267\u884c\u4ee3\u7801\uff0c\u5e76\u5728\u5355\u5143\u4e0b\u65b9\u770b\u5230\u8f93\u51fa\u7ed3\u679c\u3002\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2aNotebook\u4e2d\u7ec4\u7ec7\u548c\u8fd0\u884c\u591a\u4e2a\u4ee3\u7801\u5355\u5143\uff0c\u65b9\u4fbf\u8fdb\u884c\u6570\u636e\u5206\u6790\u3001\u53ef\u89c6\u5316\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>4\u3001\u4fdd\u5b58\u548c\u5206\u4eabNotebook<\/h3>\n<\/p>\n<p><p>Jupyter Notebook\u652f\u6301\u5c06Notebook\u4fdd\u5b58\u4e3a<code>.ipynb<\/code>\u6587\u4ef6\uff0c\u65b9\u4fbf\u65e5\u540e\u67e5\u770b\u548c\u4fee\u6539\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u9875\u9762\u4e0a\u7684\u201cFile\u201d-&gt;\u201cSave and Checkpoint\u201d\u4fdd\u5b58\u5f53\u524dNotebook\u3002\u6b64\u5916\uff0cJupyter Notebook\u8fd8\u652f\u6301\u5c06Notebook\u5bfc\u51fa\u4e3a\u591a\u79cd\u683c\u5f0f\uff0c\u5982HTML\u3001PDF\u7b49\uff0c\u65b9\u4fbf\u5206\u4eab\u548c\u5c55\u793a\u3002<\/p>\n<\/p>\n<p><h3>5\u3001Jupyter Notebook\u7684\u4f18\u52bf<\/h3>\n<\/p>\n<p><p>Jupyter Notebook\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u5f3a\u5927\u7684\u4ea4\u4e92\u6027\u548c\u53ef\u89c6\u5316\u80fd\u529b\u3002\u4f60\u53ef\u4ee5\u5728Notebook\u4e2d\u9010\u6b65\u7f16\u5199\u548c\u6267\u884c\u4ee3\u7801\uff0c\u5e76\u5b9e\u65f6\u67e5\u770b\u8f93\u51fa\u7ed3\u679c\u3002Notebook\u8fd8\u652f\u6301Markdown\u8bed\u6cd5\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u5355\u5143\u4e4b\u95f4\u63d2\u5165\u6587\u672c\u8bf4\u660e\uff0c\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7ec4\u7ec7\u548c\u8bb0\u5f55\u5206\u6790\u8fc7\u7a0b\u3002Jupyter Notebook\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u3001\u673a\u5668\u5b66\u4e60\u7b49\u9886\u57df\uff0c\u662f\u5b66\u4e60\u548c\u7814\u7a76Python\u7684\u7406\u60f3\u5de5\u5177\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e94\u3001\u901a\u8fc7Python\u811a\u672c\u81ea\u52a8\u5316\u4efb\u52a1<\/h2>\n<\/p>\n<p><h3>1\u3001\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c<\/h3>\n<\/p>\n<p><p>Python\u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u81ea\u52a8\u5316\u4efb\u52a1\u3002\u4f60\u53ef\u4ee5\u7f16\u5199Python\u811a\u672c\u6765\u81ea\u52a8\u6267\u884c\u91cd\u590d\u6027\u4efb\u52a1\uff0c\u5982\u6587\u4ef6\u64cd\u4f5c\u3001\u6570\u636e\u5904\u7406\u3001\u7f51\u7edc\u8bf7\u6c42\u7b49\u3002\u4f8b\u5982\uff0c\u7f16\u5199\u4e00\u4e2a\u811a\u672c\u81ea\u52a8\u5c06\u7279\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u672c\u6587\u4ef6\u5408\u5e76\u4e3a\u4e00\u4e2a\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>def merge_text_files(directory):<\/p>\n<p>    with open(&#39;merged.txt&#39;, &#39;w&#39;) as outfile:<\/p>\n<p>        for filename in os.listdir(directory):<\/p>\n<p>            if filename.endswith(&#39;.txt&#39;):<\/p>\n<p>                with open(os.path.join(directory, filename), &#39;r&#39;) as infile:<\/p>\n<p>                    outfile.write(infile.read())<\/p>\n<p>                    outfile.write(&#39;\\n&#39;)<\/p>\n<p>merge_text_files(&#39;path\/to\/your\/directory&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8c03\u8bd5\u548c\u4f18\u5316\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\u548c\u95ee\u9898\u3002\u53ef\u4ee5\u4f7f\u7528Python\u63d0\u4f9b\u7684\u8c03\u8bd5\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u5982<code>print<\/code>\u8c03\u8bd5\u3001\u4f7f\u7528<code>pdb<\/code>\u6a21\u5757\u7b49\uff0c\u9010\u6b65\u68c0\u67e5\u548c\u4fee\u590d\u811a\u672c\u4e2d\u7684\u9519\u8bef\u3002\u6b64\u5916\uff0c\u4f18\u5316\u811a\u672c\u7684\u6267\u884c\u6548\u7387\u548c\u53ef\u9760\u6027\u4e5f\u662f\u4e00\u4e2a\u91cd\u8981\u73af\u8282\uff0c\u53ef\u4ee5\u901a\u8fc7\u5408\u7406\u7684\u7b97\u6cd5\u548c\u6570\u636e\u7ed3\u6784\u3001\u5904\u7406\u5f02\u5e38\u60c5\u51b5\u7b49\u65b9\u5f0f\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u5b9a\u65f6\u6267\u884c\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5b9a\u671f\u6267\u884c\u67d0\u4e9b\u81ea\u52a8\u5316\u4efb\u52a1\u3002\u53ef\u4ee5\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u4efb\u52a1\u8c03\u5ea6\u5de5\u5177\uff0c\u5982Windows\u7684\u201c\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u201d\u3001macOS\u548cLinux\u7684<code>cron<\/code>\u7b49\uff0c\u5b9a\u65f6\u8fd0\u884cPython\u811a\u672c\u3002\u4f8b\u5982\uff0c\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>crontab<\/code>\u5b9a\u65f6\u6267\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">crontab -e<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6253\u5f00\u7684\u7f16\u8f91\u5668\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff0c\u5c06\u811a\u672c\u8bbe\u7f6e\u4e3a\u6bcf\u5929\u51cc\u66681\u70b9\u6267\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">0 1 * * * \/usr\/bin\/python3 \/path\/to\/your\/script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u76d1\u63a7\u548c\u7ef4\u62a4\u81ea\u52a8\u5316\u4efb\u52a1<\/h3>\n<\/p>\n<p><p>\u5728\u81ea\u52a8\u5316\u4efb\u52a1\u7684\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u5f02\u5e38\u548c\u95ee\u9898\u3002\u53ef\u4ee5\u901a\u8fc7\u8bb0\u5f55\u65e5\u5fd7\u3001\u53d1\u9001\u901a\u77e5\u7b49\u65b9\u5f0f\uff0c\u5b9e\u65f6\u76d1\u63a7\u4efb\u52a1\u7684\u6267\u884c\u60c5\u51b5\uff0c\u53ca\u65f6\u53d1\u73b0\u548c\u5904\u7406\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>logging<\/code>\u6a21\u5757\u8bb0\u5f55\u811a\u672c\u8fd0\u884c\u65e5\u5fd7\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import logging<\/p>\n<p>logging.basicConfig(filename=&#39;script.log&#39;, level=logging.INFO)<\/p>\n<p>logging.info(&#39;Script started&#39;)<\/p>\n<h2><strong>Your script code here<\/strong><\/h2>\n<p>logging.info(&#39;Script finished&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>5\u3001\u6269\u5c55\u548c\u4f18\u5316\u81ea\u52a8\u5316\u4efb\u52a1<\/h3>\n<\/p>\n<p><p>\u968f\u7740\u9700\u6c42\u7684\u53d8\u5316\u548c\u589e\u52a0\uff0c\u53ef\u80fd\u9700\u8981\u6269\u5c55\u548c\u4f18\u5316\u81ea\u52a8\u5316\u4efb\u52a1\u3002\u53ef\u4ee5\u901a\u8fc7\u6a21\u5757\u5316\u548c\u51fd\u6570\u5316\u7684\u7f16\u7a0b\u65b9\u5f0f\uff0c\u65b9\u4fbf\u5730\u6dfb\u52a0\u548c\u4fee\u6539\u529f\u80fd\uff0c\u63d0\u9ad8\u811a\u672c\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u5229\u7528Python\u4e30\u5bcc\u7684\u7b2c\u4e09\u65b9\u5e93\u548c\u5de5\u5177\uff0c\u5982<code>requests<\/code>\u3001<code>pandas<\/code>\u3001<code>beautifulsoup4<\/code>\u7b49\uff0c\u63d0\u5347\u811a\u672c\u7684\u529f\u80fd\u548c\u6027\u80fd\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u516d\u3001\u5728Web\u5f00\u53d1\u4e2d\u7684\u5e94\u7528<\/h2>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528Flask\u6784\u5efaWeb\u5e94\u7528<\/h3>\n<\/p>\n<p><p>Flask\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Python Web\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u6784\u5efa\u5c0f\u578b\u5230\u4e2d\u578b\u7684Web\u5e94\u7528\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7<code>pip<\/code>\u547d\u4ee4\u5b89\u88c5Flask\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install flask<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Flask\u5e94\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/&#39;)<\/p>\n<p>def hello_world():<\/p>\n<p>    return &#39;Hello, World!&#39;<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u4e3a<code>app.py<\/code>\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c<code>python app.py<\/code>\uff0c\u7136\u540e\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00<code>http:\/\/127.0.0.1:5000\/<\/code>\uff0c\u4f60\u4f1a\u770b\u5230\u8f93\u51fa<code>Hello, World!<\/code>\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528Django\u6784\u5efaWeb\u5e94\u7528<\/h3>\n<\/p>\n<p><p>Django\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684Python Web\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u6784\u5efa\u5927\u578b\u590d\u6742\u7684Web\u5e94\u7528\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7<code>pip<\/code>\u547d\u4ee4\u5b89\u88c5Django\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install django<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Django\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">django-admin startproject myproject<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\uff0c\u8fd0\u884c\u5f00\u53d1\u670d\u52a1\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">cd myproject<\/p>\n<p>python manage.py runserver<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00<code>http:\/\/127.0.0.1:8000\/<\/code>\uff0c\u4f60\u4f1a\u770b\u5230Django\u7684\u6b22\u8fce\u9875\u9762\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u521b\u5efa\u548c\u914d\u7f6e\u5e94\u7528\u3001\u7f16\u5199\u89c6\u56fe\u548c\u6a21\u677f\u3001\u8bbe\u7f6e\u8def\u7531\u7b49\uff0c\u6784\u5efa\u529f\u80fd\u4e30\u5bcc\u7684Web\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>3\u3001RESTful API\u7684\u5f00\u53d1<\/h3>\n<\/p>\n<p><p>\u5728\u73b0\u4ee3Web\u5f00\u53d1\u4e2d\uff0cRESTful API\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u63a5\u53e3\u8bbe\u8ba1\u98ce\u683c\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Flask\u6216Django\u6784\u5efaRESTful API\uff0c\u63d0\u4f9b\u6570\u636e\u63a5\u53e3\u4f9b\u524d\u7aef\u6216\u5176\u4ed6\u670d\u52a1\u8c03\u7528\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Flask\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684RESTful API\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, jsonify, request<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>data = [<\/p>\n<p>    {&#39;id&#39;: 1, &#39;name&#39;: &#39;Alice&#39;},<\/p>\n<p>    {&#39;id&#39;: 2, &#39;name&#39;: &#39;Bob&#39;}<\/p>\n<p>]<\/p>\n<p>@app.route(&#39;\/api\/data&#39;, methods=[&#39;GET&#39;])<\/p>\n<p>def get_data():<\/p>\n<p>    return jsonify(data)<\/p>\n<p>@app.route(&#39;\/api\/data&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def add_data():<\/p>\n<p>    new_data = request.json<\/p>\n<p>    data.append(new_data)<\/p>\n<p>    return jsonify(new_data), 201<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u4e3a<code>api.py<\/code>\uff0c\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c<code>python api.py<\/code>\uff0c\u7136\u540e\u53ef\u4ee5\u901a\u8fc7<code>GET<\/code>\u548c<code>POST<\/code>\u8bf7\u6c42\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>4\u3001Web\u5e94\u7528\u7684\u90e8\u7f72\u548c\u7ef4\u62a4<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u5b8c\u6210\u540e\uff0c\u9700\u8981\u5c06Web\u5e94\u7528\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u4e2d\u3002\u53ef\u4ee5\u9009\u62e9\u5404\u79cd\u90e8\u7f72\u65b9\u5f0f\u548c\u5e73\u53f0\uff0c\u5982\u4e91\u670d\u52a1\u5668\uff08AWS\u3001Azure\u3001Google Cloud\u7b49\uff09\u3001PaaS\u5e73\u53f0\uff08Heroku\u3001PythonAnywhere\u7b49\uff09\u3001\u5bb9\u5668\u5316\u90e8\u7f72\uff08Docker\u3001Kubernetes\u7b49\uff09\u3002\u90e8\u7f72\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u914d\u7f6e\u670d\u52a1\u5668\u73af\u5883\u3001\u8bbe\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u3001\u7ba1\u7406\u9759\u6001\u6587\u4ef6\u7b49\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u7ef4\u62a4\u548c\u66f4\u65b0Web\u5e94\u7528\uff0c\u76d1\u63a7\u8fd0\u884c\u72b6\u6001\uff0c\u786e\u4fdd\u5e94\u7528\u7684\u7a33\u5b9a\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<p><h3>5\u3001Web\u5f00\u53d1\u4e2d\u7684\u5b89\u5168\u548c\u6027\u80fd\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u5728Web\u5f00\u53d1\u4e2d\uff0c\u5b89\u5168\u548c\u6027\u80fd\u662f\u4e24\u4e2a\u91cd\u8981\u7684\u65b9\u9762\u3002\u9700\u8981\u91c7\u53d6\u5404\u79cd\u63aa\u65bd\u4fdd\u969c\u5e94\u7528\u7684\u5b89\u5168\uff0c\u5982\u9632\u8303SQL\u6ce8\u5165\u3001XSS\u653b\u51fb\u3001CSRF\u653b\u51fb\u7b49\uff0c\u4fdd\u62a4\u7528\u6237\u6570\u636e\u548c\u9690\u79c1\u3002\u6027\u80fd\u4f18\u5316\u65b9\u9762\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f13\u5b58\u3001\u8d1f\u8f7d\u5747\u8861\u3001\u6570\u636e\u5e93\u4f18\u5316\u7b49\u65b9\u5f0f\uff0c\u63d0\u9ad8\u5e94\u7528\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u5904\u7406\u80fd\u529b\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u8fdb\u884c<a href=\"https:\/\/docs.pingcode.com\/code-review\" target=\"_blank\">\u4ee3\u7801\u5ba1\u67e5<\/a>\u548c\u6d4b\u8bd5\uff0c\u53d1\u73b0\u548c\u4fee\u590d\u6f5c\u5728\u7684\u95ee\u9898\uff0c\u63d0\u5347\u5e94\u7528\u7684\u8d28\u91cf\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e03\u3001\u6570\u636e\u5206\u6790\u4e0e\u53ef\u89c6\u5316<\/h2>\n<\/p>\n<p><h3>1\u3001\u6570\u636e\u5206\u6790\u5de5\u5177\u548c\u5e93<\/h3>\n<\/p>\n<p><p>Python\u5728\u6570\u636e\u5206\u6790\u9886\u57df\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u5f3a\u5927\u7684\u5de5\u5177\u548c\u5e93\uff0c\u5982<code>pandas<\/code>\u3001<code>numpy<\/code>\u3001<code>scipy<\/code>\u7b49\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>pandas<\/code>\u8bfb\u53d6\u548c\u5206\u6790CSV\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u57fa\u672c\u4fe1\u606f<\/strong><\/h2>\n<p>print(data.info())<\/p>\n<h2><strong>\u7edf\u8ba1\u6570\u636e\u63cf\u8ff0<\/strong><\/h2>\n<p>print(data.describe())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u6570\u636e\u53ef\u89c6\u5316\u5de5\u5177\u548c\u5e93<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u53ef\u89c6\u5316\u662f\u6570\u636e\u5206\u6790\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u53ef\u4ee5\u5e2e\u52a9\u66f4\u76f4\u89c2\u5730\u7406\u89e3\u548c\u5c55\u793a\u6570\u636e\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u6570\u636e\u53ef\u89c6\u5316\u5de5\u5177\u548c\u5e93\uff0c\u5982<code>matplotlib<\/code>\u3001<code>seaborn<\/code>\u3001<code>plotly<\/code>\u7b49\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>matplotlib<\/code>\u7ed8\u5236\u6570\u636e\u5206\u5e03\u56fe\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u7ed8\u5236\u6570\u636e\u5206\u5e03\u56fe<\/strong><\/h2>\n<p>plt.hist(data[&#39;column_name&#39;], bins=20)<\/p>\n<p>plt.xlabel(&#39;Value&#39;)<\/p>\n<p>plt.ylabel(&#39;Frequency&#39;)<\/p>\n<p>plt.title(&#39;Data Distribution&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u6570\u636e\u6e05\u6d17\u548c\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6570\u636e\u5206\u6790\u4e4b\u524d\uff0c\u901a\u5e38\u9700\u8981\u5bf9\u539f\u59cb\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u9884\u5904\u7406\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u8d28\u91cf\u548c\u4e00\u81f4\u6027\u3002\u4f8b\u5982\uff0c\u5904\u7406\u7f3a\u5931\u503c\u3001\u53bb\u9664\u91cd\u590d\u6570\u636e\u3001\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u63d0\u4f9b\u7684\u5404\u79cd\u51fd\u6570\u548c\u65b9\u6cd5\uff0c\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u548c\u9884\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5904\u7406\u7f3a\u5931\u503c<\/p>\n<p>data = data.dropna()<\/p>\n<h2><strong>\u53bb\u9664\u91cd\u590d\u6570\u636e<\/strong><\/h2>\n<p>data = data.drop_duplicates()<\/p>\n<h2><strong>\u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/strong><\/h2>\n<p>data[&#39;column_name&#39;] = data[&#39;column_name&#39;].astype(&#39;int&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u6570\u636e\u5206\u6790\u548c\u5efa\u6a21<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u5206\u6790\u548c\u5efa\u6a21\u662f\u6570\u636e\u79d1\u5b66\u7684\u6838\u5fc3\u6b65\u9aa4\uff0c\u901a\u8fc7\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790\uff08EDA\uff09\u3001\u7279\u5f81\u5de5\u7a0b\u3001\u6a21\u578b\u8bad\u7ec3\u548c\u8bc4\u4f30\u7b49\u8fc7\u7a0b\uff0c\u4ece\u6570\u636e\u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u548c\u6a21\u5f0f\u3002\u4f8b\u5982\uff0c\u4f7f\u7528`scikit-le<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5f00\u59cb\u7f16\u5199\u7a0b\u5e8f\uff1f<\/strong><br \/>\u8981\u5f00\u59cb\u7f16\u5199Python\u7a0b\u5e8f\uff0c\u60a8\u9700\u8981\u5b89\u88c5Python\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u7248\u672c\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u5982PyCharm\u3001VSCode\u6216Jupyter Notebook\uff0c\u521b\u5efa\u548c\u7f16\u8f91\u60a8\u7684Python\u6587\u4ef6\u3002\u786e\u4fdd\u6587\u4ef6\u4ee5\u201c.py\u201d\u6269\u5c55\u540d\u4fdd\u5b58\uff0c\u8fd9\u6837\u60a8\u5c31\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8fd0\u884c\u5b83\u4eec\u3002<\/p>\n<p><strong>\u4f7f\u7528\u54ea\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u6211\u66f4\u6709\u6548\u5730\u7f16\u5199Python\u7a0b\u5e8f\uff1f<\/strong><br \/>\u6709\u8bb8\u591a\u5de5\u5177\u53ef\u4ee5\u63d0\u9ad8\u60a8\u7f16\u5199Python\u7a0b\u5e8f\u7684\u6548\u7387\u3002\u5e38\u7528\u7684IDE\u5305\u62ecPyCharm\u3001Visual Studio Code\u548cSpyder\u7b49\uff0c\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4ee3\u7801\u9ad8\u4eae\u3001\u81ea\u52a8\u8865\u5168\u548c\u8c03\u8bd5\u529f\u80fd\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u5982Git\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7ba1\u7406\u4ee3\u7801\u7248\u672c\uff0c\u786e\u4fdd\u7a0b\u5e8f\u7684\u5b89\u5168\u548c\u53ef\u8ffd\u6eaf\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5Python\u7a0b\u5e8f\u4ee5\u627e\u5230\u9519\u8bef\uff1f<\/strong><br \/>\u8c03\u8bd5Python\u7a0b\u5e8f\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u6cd5\u8fdb\u884c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>print()<\/code>\u51fd\u6570\u5728\u5173\u952e\u4f4d\u7f6e\u6253\u5370\u53d8\u91cf\u503c\uff0c\u4ee5\u68c0\u67e5\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\uff0c\u5982Python\u7684<code>pdb<\/code>\u6a21\u5757\u6216IDE\u81ea\u5e26\u7684\u8c03\u8bd5\u5668\uff0c\u8bbe\u7f6e\u65ad\u70b9\u5e76\u9010\u6b65\u6267\u884c\u4ee3\u7801\uff0c\u4ee5\u4fbf\u66f4\u6df1\u5165\u5730\u4e86\u89e3\u95ee\u9898\u6240\u5728\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u66f4\u5feb\u5730\u627e\u5230\u5e76\u4fee\u590d\u9519\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8fdb\u5165\u7a0b\u5e8f\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u5728\u4ea4\u4e92\u5f0f [&hellip;]","protected":false},"author":3,"featured_media":1178171,"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\/1178163"}],"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=1178163"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1178163\/revisions"}],"predecessor-version":[{"id":1178174,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1178163\/revisions\/1178174"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1178171"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1178163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1178163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1178163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}