{"id":1045457,"date":"2024-12-31T13:23:16","date_gmt":"2024-12-31T05:23:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1045457.html"},"modified":"2024-12-31T13:23:18","modified_gmt":"2024-12-31T05:23:18","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e8%87%aa%e5%b7%b1%e7%9a%84%e7%94%b5%e8%84%91%e4%b8%8a%e5%86%99python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1045457.html","title":{"rendered":"\u5982\u4f55\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5199python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/e90b1d3a-cdf7-411d-8b4a-86b34932d113.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5199python\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5199Python<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5199Python\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<strong>\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u9009\u62e9\u5408\u9002\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883\u3001\u5b66\u4e60\u57fa\u672c\u8bed\u6cd5\u548c\u5e93\u3001\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801<\/strong>\u7b49\u6b65\u9aa4\u3002\u4e3a\u4e86\u66f4\u8be6\u7ec6\u5730\u4e86\u89e3\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u8ba8\u8bba\u5982\u4f55\u5b89\u88c5Python\u89e3\u91ca\u5668\u548c\u9009\u62e9\u5408\u9002\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python\u89e3\u91ca\u5668<\/p>\n<\/p>\n<p><p>\u5b89\u88c5Python\u89e3\u91ca\u5668\u662f\u5f00\u59cb\u7f16\u5199Python\u4ee3\u7801\u7684\u7b2c\u4e00\u6b65\u3002Python\u89e3\u91ca\u5668\u662f\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5b83\u53ef\u4ee5\u8bfb\u53d6\u5e76\u6267\u884cPython\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u5b89\u88c5Python\u89e3\u91ca\u5668\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4e0b\u8f7dPython\u89e3\u91ca\u5668<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.python.org\/%EF%BC%89%E3%80%82\">https:\/\/www.python.org\/\uff09\u3002<\/a><\/li>\n<li>\u5728\u7f51\u7ad9\u9996\u9875\uff0c\u70b9\u51fb\u201cDownloads\u201d\u9009\u9879\uff0c\u5e76\u9009\u62e9\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684Python\u7248\u672c\uff08Windows\u3001MacOS\u6216Linux\uff09\u3002<\/li>\n<li>\u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u5efa\u8bae\u4e0b\u8f7d\u6700\u65b0\u7684\u7a33\u5b9a\u7248\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5Python\u89e3\u91ca\u5668<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u5b89\u88c5\u7a0b\u5e8f\u3002<\/li>\n<li>\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u4f1a\u5c06Python\u89e3\u91ca\u5668\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u65b9\u4fbf\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528\u3002<\/li>\n<li>\u70b9\u51fb\u201cInstall Now\u201d\u6309\u94ae\uff0c\u7b49\u5f85\u5b89\u88c5\u5b8c\u6210\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff08Windows\uff1a\u547d\u4ee4\u63d0\u793a\u7b26\uff1bMacOS\u548cLinux\uff1a\u7ec8\u7aef\uff09\u3002<\/li>\n<li>\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\uff0c\u67e5\u770bPython\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u663e\u793a\u7248\u672c\u53f7\uff0c\u8bf4\u660ePython\u89e3\u91ca\u5668\u5df2\u6210\u529f\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p><strong>\u9009\u62e9\u5408\u9002\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/strong><\/p>\n<\/p>\n<p><p>\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7f16\u5199Python\u4ee3\u7801\u7684\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u548cIDE\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Visual Studio Code (VS Code)<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5b89\u88c5VS Code<\/strong>\uff1a\n<ul>\n<li>\u8bbf\u95eeVisual Studio Code\u7684\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/code.visualstudio.com\/%EF%BC%89%E3%80%82\">https:\/\/code.visualstudio.com\/\uff09\u3002<\/a><\/li>\n<li>\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\uff0c\u5e76\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u914d\u7f6ePython\u6269\u5c55<\/strong>\uff1a\n<ul>\n<li>\u6253\u5f00VS Code\uff0c\u70b9\u51fb\u5de6\u4fa7\u6d3b\u52a8\u680f\u4e2d\u7684\u6269\u5c55\u56fe\u6807\uff08\u56db\u4e2a\u65b9\u5757\u62fc\u6210\u7684\u56fe\u6848\uff09\u3002<\/li>\n<li>\u5728\u641c\u7d22\u680f\u4e2d\u8f93\u5165\u201cPython\u201d\uff0c\u627e\u5230\u7531Microsoft\u53d1\u5e03\u7684Python\u6269\u5c55\uff0c\u5e76\u70b9\u51fb\u201cInstall\u201d\u6309\u94ae\u3002<\/li>\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0cVS Code\u5c06\u81ea\u52a8\u914d\u7f6ePython\u73af\u5883\uff0c\u5e76\u4e3a\u60a8\u63d0\u4f9b\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u7b49\u529f\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>PyCharm<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5b89\u88c5PyCharm<\/strong>\uff1a\n<ul>\n<li>\u8bbf\u95eePyCharm\u7684\u5b98\u65b9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.jetbrains.com\/pycharm\/%EF%BC%89%E3%80%82\">https:\/\/www.jetbr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns.com\/pycharm\/\uff09\u3002<\/a><\/li>\n<li>\u4e0b\u8f7d\u9002\u5408\u60a8\u9700\u6c42\u7684\u7248\u672c\uff08\u793e\u533a\u7248\u514d\u8d39\uff0c\u4e13\u4e1a\u7248\u6536\u8d39\uff09\uff0c\u5e76\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u521b\u5efa\u65b0\u9879\u76ee<\/strong>\uff1a\n<ul>\n<li>\u6253\u5f00PyCharm\uff0c\u70b9\u51fb\u201cCreate New Project\u201d\u6309\u94ae\u3002<\/li>\n<li>\u9009\u62e9\u9879\u76ee\u7684\u5b58\u50a8\u4f4d\u7f6e\uff0c\u5e76\u9009\u62e9\u60a8\u5df2\u5b89\u88c5\u7684Python\u89e3\u91ca\u5668\u3002<\/li>\n<li>\u70b9\u51fb\u201cCreate\u201d\u6309\u94ae\uff0cPyCharm\u5c06\u4e3a\u60a8\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u9879\u76ee\uff0c\u5e76\u81ea\u52a8\u914d\u7f6e\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Jupyter Notebook<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u5b89\u88c5Jupyter Notebook<\/strong>\uff1a\n<ul>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165<code>pip install notebook<\/code>\uff0c\u7b49\u5f85\u5b89\u88c5\u5b8c\u6210\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u542f\u52a8Jupyter Notebook<\/strong>\uff1a\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u5de5\u5177\u4e2d\u8f93\u5165<code>jupyter notebook<\/code>\uff0c\u8fd9\u5c06\u542f\u52a8Jupyter Notebook\uff0c\u5e76\u5728\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u521b\u5efa\u65b0\u7b14\u8bb0\u672c<\/strong>\uff1a\n<ul>\n<li>\u5728\u6d4f\u89c8\u5668\u4e2d\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201cNew\u201d\u6309\u94ae\uff0c\u5e76\u9009\u62e9\u201cPython 3\u201d\u3002<\/li>\n<li>\u60a8\u73b0\u5728\u53ef\u4ee5\u5728\u65b0\u5efa\u7684\u7b14\u8bb0\u672c\u4e2d\u7f16\u5199\u5e76\u8fd0\u884cPython\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883<\/p>\n<\/p>\n<p><p>\u914d\u7f6e\u865a\u62df\u73af\u5883\u662f\u7ba1\u7406Python\u9879\u76ee\u4f9d\u8d56\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u865a\u62df\u73af\u5883\u53ef\u4ee5\u9694\u79bb\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u907f\u514d\u7248\u672c\u51b2\u7a81\u3002\u4ee5\u4e0b\u662f\u914d\u7f6e\u865a\u62df\u73af\u5883\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5virtualenv<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165<code>pip install virtualenv<\/code>\uff0c\u7b49\u5f85\u5b89\u88c5\u5b8c\u6210\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u8f93\u5165<code>virtualenv venv<\/code>\uff0c\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cvenv\u201d\u7684\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>Windows\uff1a\u5728\u547d\u4ee4\u884c\u5de5\u5177\u4e2d\u8f93\u5165<code>venv\\Scripts\\activate<\/code>\u3002<\/li>\n<li>MacOS\u548cLinux\uff1a\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>source venv\/bin\/activate<\/code>\u3002<\/li>\n<li>\u6fc0\u6d3b\u540e\uff0c\u60a8\u5c06\u770b\u5230\u547d\u4ee4\u63d0\u793a\u7b26\u524d\u9762\u51fa\u73b0\u201c(venv)\u201d\u5b57\u6837\uff0c\u8868\u793a\u865a\u62df\u73af\u5883\u5df2\u6210\u529f\u6fc0\u6d3b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f7f\u7528<code>pip install<\/code>\u547d\u4ee4\u5b89\u88c5\u9879\u76ee\u6240\u9700\u7684\u4f9d\u8d56\u5e93\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u8f93\u5165<code>pip install requests<\/code>\u5b89\u88c5requests\u5e93\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u8f93\u5165<code>deactivate<\/code>\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5b66\u4e60\u57fa\u672c\u8bed\u6cd5\u548c\u5e93<\/p>\n<\/p>\n<p><p>\u5b66\u4e60Python\u7684\u57fa\u672c\u8bed\u6cd5\u548c\u5e38\u7528\u5e93\u662f\u7f16\u5199\u9ad8\u6548\u4ee3\u7801\u7684\u57fa\u7840\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684Python\u8bed\u6cd5\u548c\u5e93\u7684\u4ecb\u7ecd\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b<\/strong>\uff1a\n<ul>\n<li>Python\u652f\u6301\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5982\u6574\u6570\uff08int\uff09\u3001\u6d6e\u70b9\u6570\uff08float\uff09\u3001\u5b57\u7b26\u4e32\uff08str\uff09\u548c\u5e03\u5c14\u503c\uff08bool\uff09\u3002<\/li>\n<li>\u53d8\u91cf\u65e0\u9700\u663e\u5f0f\u58f0\u660e\u7c7b\u578b\uff0c\u76f4\u63a5\u8d4b\u503c\u5373\u53ef\u3002<\/li>\n<li>\u4f8b\u5982\uff0c<code>x = 10<\/code>\u3001<code>y = 3.14<\/code>\u3001<code>name = &quot;Alice&quot;<\/code>\u3001<code>is_active = True<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u63a7\u5236\u7ed3\u6784<\/strong>\uff1a\n<ul>\n<li>Python\u652f\u6301\u6761\u4ef6\u8bed\u53e5\uff08if-elif-else\uff09\u3001\u5faa\u73af\u8bed\u53e5\uff08for\u548cwhile\uff09\u7b49\u3002<\/li>\n<li>\u4f8b\u5982\uff1a\n<pre><code class=\"language-python\">if x &gt; 0:<\/p>\n<p>    print(&quot;x is positive&quot;)<\/p>\n<p>elif x == 0:<\/p>\n<p>    print(&quot;x is zero&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;x is negative&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u51fd\u6570\u548c\u7c7b<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u51fd\u6570\uff0c\u4f7f\u7528<code>class<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u7c7b\u3002<\/li>\n<li>\u4f8b\u5982\uff1a\n<pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    return f&quot;Hello, {name}!&quot;<\/p>\n<p>class Person:<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        self.name = name<\/p>\n<p>        self.age = age<\/p>\n<p>    def introduce(self):<\/p>\n<p>        return f&quot;My name is {self.name}, and I am {self.age} years old.&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5e38\u7528\u5e93<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>NumPy<\/strong>\uff1a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u5e93\uff0c\u63d0\u4f9b\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u5404\u79cd\u6570\u5b66\u51fd\u6570\u3002\n<ul>\n<li>\u5b89\u88c5\uff1a<code>pip install numpy<\/code><\/li>\n<li>\u4f7f\u7528\u793a\u4f8b\uff1a\n<pre><code class=\"language-python\">import numpy as np<\/p>\n<p>arr = np.array([1, 2, 3, 4, 5])<\/p>\n<p>print(arr.mean())  # \u8ba1\u7b97\u5747\u503c<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Pandas<\/strong>\uff1a\u7528\u4e8e\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u7684\u5e93\uff0c\u63d0\u4f9b\u6570\u636e\u5e27\u5bf9\u8c61\u548c\u6570\u636e\u64cd\u4f5c\u51fd\u6570\u3002\n<ul>\n<li>\u5b89\u88c5\uff1a<code>pip install pandas<\/code><\/li>\n<li>\u4f7f\u7528\u793a\u4f8b\uff1a\n<pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = {&#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;], &#39;Age&#39;: [25, 30, 35]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Matplotlib<\/strong>\uff1a\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u7684\u5e93\uff0c\u63d0\u4f9b\u7ed8\u56fe\u51fd\u6570\u3002\n<ul>\n<li>\u5b89\u88c5\uff1a<code>pip install matplotlib<\/code><\/li>\n<li>\u4f7f\u7528\u793a\u4f8b\uff1a\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [1, 4, 9, 16, 25]<\/p>\n<p>plt.plot(x, y)<\/p>\n<p>plt.xlabel(&#39;X-axis&#39;)<\/p>\n<p>plt.ylabel(&#39;Y-axis&#39;)<\/p>\n<p>plt.title(&#39;Simple Plot&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Requests<\/strong>\uff1a\u7528\u4e8e\u53d1\u9001HTTP\u8bf7\u6c42\u7684\u5e93\uff0c\u7b80\u5316\u4e86\u7f51\u7edc\u8bf7\u6c42\u64cd\u4f5c\u3002\n<ul>\n<li>\u5b89\u88c5\uff1a<code>pip install requests<\/code><\/li>\n<li>\u4f7f\u7528\u793a\u4f8b\uff1a\n<pre><code class=\"language-python\">import requests<\/p>\n<p>response = requests.get(&#39;https:\/\/api.github.com&#39;)<\/p>\n<p>print(response.status_code)<\/p>\n<p>print(response.json())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u5728\u4e86\u89e3\u57fa\u672c\u8bed\u6cd5\u548c\u5e38\u7528\u5e93\u540e\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801\u7684\u5b9e\u7528\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u9009\u62e9\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u6216IDE\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\uff08\u4ee5<code>.py<\/code>\u4e3a\u6269\u5c55\u540d\uff09\u3002<\/li>\n<li>\u7f16\u5199Python\u4ee3\u7801\uff0c\u5e76\u4fdd\u5b58\u6587\u4ef6\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>hello.py<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a\n<pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    return f&quot;Hello, {name}!&quot;<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    name = input(&quot;Enter your name: &quot;)<\/p>\n<p>    print(greet(name))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884c\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u5bfc\u822a\u5230Python\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u3002<\/li>\n<li>\u8f93\u5165<code>python hello.py<\/code>\u6216<code>python3 hello.py<\/code>\uff0c\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<li>\u7a0b\u5e8f\u5c06\u63d0\u793a\u60a8\u8f93\u5165\u59d3\u540d\uff0c\u5e76\u8f93\u51fa\u95ee\u5019\u8bed\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8c03\u8bd5\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u4ee3\u7801\u7f16\u8f91\u5668\u6216IDE\u63d0\u4f9b\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u8bbe\u7f6e\u65ad\u70b9\u5e76\u9010\u6b65\u6267\u884c\u4ee3\u7801\uff0c\u67e5\u627e\u548c\u4fee\u590d\u9519\u8bef\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u5728VS Code\u4e2d\uff0c\u70b9\u51fb\u884c\u53f7\u5de6\u4fa7\u7684\u7a7a\u767d\u5904\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7136\u540e\u70b9\u51fb\u8c03\u8bd5\u56fe\u6807\uff08\u5c0f\u866b\u5b50\u56fe\u6807\uff09\u542f\u52a8\u8c03\u8bd5\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u8fdb\u9636\u6280\u5de7\u548c\u6700\u4f73\u5b9e\u8df5<\/p>\n<\/p>\n<p><p>\u5728\u638c\u63e1\u57fa\u672c\u6280\u80fd\u540e\uff0c\u60a8\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347Python\u7f16\u7a0b\u80fd\u529b\uff0c\u5b66\u4e60\u8fdb\u9636\u6280\u5de7\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08OOP\uff09<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u662f\u4e00\u79cd\u7f16\u7a0b\u8303\u5f0f\uff0c\u901a\u8fc7\u5b9a\u4e49\u7c7b\u548c\u5bf9\u8c61\u7ec4\u7ec7\u4ee3\u7801\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/li>\n<li>\u4f8b\u5982\uff1a\n<pre><code class=\"language-python\">class Animal:<\/p>\n<p>    def __init__(self, name):<\/p>\n<p>        self.name = name<\/p>\n<p>    def speak(self):<\/p>\n<p>        pass<\/p>\n<p>class Dog(Animal):<\/p>\n<p>    def speak(self):<\/p>\n<p>        return f&quot;{self.name} says Woof!&quot;<\/p>\n<p>dog = Dog(&quot;Buddy&quot;)<\/p>\n<p>print(dog.speak())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u7248\u672c\u63a7\u5236\u5de5\u5177\uff08\u5982Git\uff09<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u7248\u672c\u63a7\u5236\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7ba1\u7406\u4ee3\u7801\u7684\u4e0d\u540c\u7248\u672c\uff0c\u8ddf\u8e2a\u4ee3\u7801\u53d8\u66f4\uff0c\u5e76\u4e0e\u4ed6\u4eba\u534f\u4f5c\u5f00\u53d1\u3002<\/li>\n<li>\u5b89\u88c5Git\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u5de5\u5177\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521d\u59cb\u5316Git\u4ed3\u5e93\uff1a\n<pre><code class=\"language-sh\">git init<\/p>\n<p>git add .<\/p>\n<p>git commit -m &quot;Initial commit&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9075\u5faa\u7f16\u7801\u89c4\u8303\uff08\u5982PEP 8\uff09<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u7f16\u7801\u89c4\u8303\u662f\u7f16\u5199\u6574\u6d01\u3001\u53ef\u8bfb\u4ee3\u7801\u7684\u91cd\u8981\u6307\u5357\u3002PEP 8\u662fPython\u7684\u5b98\u65b9\u7f16\u7801\u89c4\u8303\uff0c\u6db5\u76d6\u4e86\u4ee3\u7801\u683c\u5f0f\u3001\u547d\u540d\u7ea6\u5b9a\u7b49\u65b9\u9762\u3002<\/li>\n<li>\u4f8b\u5982\uff1a\n<ul>\n<li>\u4f7f\u75284\u4e2a\u7a7a\u683c\u7f29\u8fdb\u3002<\/li>\n<li>\u53d8\u91cf\u540d\u548c\u51fd\u6570\u540d\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\u548c\u4e0b\u5212\u7ebf\u5206\u9694\uff08\u5982<code>my_variable<\/code>\u3001<code>my_function<\/code>\uff09\u3002<\/li>\n<li>\u7c7b\u540d\u4f7f\u7528\u9996\u5b57\u6bcd\u5927\u5199\u7684\u9a7c\u5cf0\u547d\u540d\u6cd5\uff08\u5982<code>MyClass<\/code>\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5b66\u4e60\u5355\u5143\u6d4b\u8bd5\u548c\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1\uff08TDD\uff09<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5355\u5143\u6d4b\u8bd5\u662f\u9a8c\u8bc1\u4ee3\u7801\u529f\u80fd\u7684\u91cd\u8981\u624b\u6bb5\uff0c\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1\uff08TDD\uff09\u662f\u4e00\u79cd\u7f16\u5199\u9ad8\u8d28\u91cf\u4ee3\u7801\u7684\u65b9\u6cd5\u8bba\u3002<\/li>\n<li>\u4f7f\u7528<code>unittest<\/code>\u5e93\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\uff1a\n<pre><code class=\"language-python\">import unittest<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>class TestMath(unittest.TestCase):<\/p>\n<p>    def test_add(self):<\/p>\n<p>        self.assertEqual(add(1, 2), 3)<\/p>\n<p>        self.assertEqual(add(-1, 1), 0)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u548c\u793e\u533a<\/strong>\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u901a\u8fc7\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u548c\u793e\u533a\uff0c\u60a8\u53ef\u4ee5\u4e0e\u5176\u4ed6\u5f00\u53d1\u8005\u4ea4\u6d41\u7ecf\u9a8c\uff0c\u5b66\u4e60\u65b0\u6280\u672f\uff0c\u5e76\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002<\/li>\n<li>\u60a8\u53ef\u4ee5\u5728GitHub\u7b49\u5e73\u53f0\u4e0a\u67e5\u627e\u611f\u5174\u8da3\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u63d0\u4ea4\u4ee3\u7801\u8d21\u732e\uff08Pull Request\uff09\uff0c\u5e76\u53c2\u4e0e\u9879\u76ee\u8ba8\u8bba\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5199Python\u4ee3\u7801\uff0c\u60a8\u9700\u8981\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u9009\u62e9\u5408\u9002\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u6216IDE\u3001\u914d\u7f6e\u865a\u62df\u73af\u5883\u3001\u5b66\u4e60\u57fa\u672c\u8bed\u6cd5\u548c\u5e93\uff0c\u5e76\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801\u3002\u901a\u8fc7\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u60a8\u53ef\u4ee5\u638c\u63e1\u8fdb\u9636\u6280\u5de7\u548c\u6700\u4f73\u5b9e\u8df5\uff0c\u6210\u4e3a\u4e00\u540d\u9ad8\u6548\u7684Python\u5f00\u53d1\u8005\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u60a8\u987a\u5229\u5f00\u59cbPython\u7f16\u7a0b\u4e4b\u65c5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u6211\u7684\u7535\u8111\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728\u7535\u8111\u4e0a\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u8bbf\u95eePython\u7684\u5b98\u65b9\u7f51\u7ad9\uff08python.org\uff09\uff0c\u4e0b\u8f7d\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u8bf7\u786e\u4fdd\u52fe\u9009\u201cAdd Python to PATH\u201d\u9009\u9879\uff0c\u8fd9\u6837\u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u4f7f\u7528Python\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165<code>python --version<\/code>\u6765\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<p><strong>\u6211\u9700\u8981\u54ea\u4e9b\u5de5\u5177\u6765\u5199Python\u4ee3\u7801\uff1f<\/strong><br \/>\u7f16\u5199Python\u4ee3\u7801\u4e0d\u9700\u8981\u592a\u591a\u590d\u6742\u7684\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u7b80\u5355\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u5982Notepad\uff08\u8bb0\u4e8b\u672c\uff09\u6216\u66f4\u4e3a\u4e13\u4e1a\u7684\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u4f8b\u5982Visual Studio Code\u3001PyCharm\u6216Sublime Text\u3002\u8fd9\u4e9b\u7f16\u8f91\u5668\u63d0\u4f9b\u4e86\u8bed\u6cd5\u9ad8\u4eae\u3001\u4ee3\u7801\u8865\u5168\u7b49\u529f\u80fd\uff0c\u53ef\u4ee5\u63d0\u9ad8\u60a8\u7684\u7f16\u7a0b\u6548\u7387\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u7535\u8111\u4e0a\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8fd0\u884cPython\u811a\u672c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\u3002\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\u662f\u5728\u547d\u4ee4\u884c\u4e2d\u5bfc\u822a\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165<code>python script_name.py<\/code>\u6765\u6267\u884c\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u901a\u5e38\u53ef\u4ee5\u76f4\u63a5\u70b9\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\uff0c\u6216\u4f7f\u7528\u5feb\u6377\u952e\u6765\u6267\u884c\u4ee3\u7801\u3002\u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u4e2d\u7f16\u5199\u5e76\u4fdd\u5b58\u811a\u672c\u540e\uff0c\u901a\u8fc7\u53cc\u51fb\u811a\u672c\u6587\u4ef6\u6765\u8fd0\u884c\u5b83\uff0c\u524d\u63d0\u662f\u60a8\u7684\u7cfb\u7edf\u5df2\u5c06Python\u6587\u4ef6\u4e0ePython\u89e3\u91ca\u5668\u5173\u8054\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5199Python \u5728\u81ea\u5df1\u7684\u7535\u8111\u4e0a\u5199Python\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b89\u88c5Python\u89e3\u91ca\u5668\u3001\u9009\u62e9\u5408\u9002\u7684\u4ee3 [&hellip;]","protected":false},"author":3,"featured_media":1045471,"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\/1045457"}],"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=1045457"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1045457\/revisions"}],"predecessor-version":[{"id":1045473,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1045457\/revisions\/1045473"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1045471"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1045457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1045457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1045457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}