{"id":1076374,"date":"2025-01-08T11:52:46","date_gmt":"2025-01-08T03:52:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1076374.html"},"modified":"2025-01-08T11:52:48","modified_gmt":"2025-01-08T03:52:48","slug":"python%e7%9a%84%e5%a6%82%e4%bd%95%e5%86%99%e7%a8%8b%e5%ba%8f%e5%91%98-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1076374.html","title":{"rendered":"python\u7684\u5982\u4f55\u5199\u7a0b\u5e8f\u5458"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180953\/bb37c7fb-e664-4077-a32f-f1723d8ce57e.webp\" alt=\"python\u7684\u5982\u4f55\u5199\u7a0b\u5e8f\u5458\" \/><\/p>\n<p><h3>PYTHON\u5982\u4f55\u5199\u7a0b\u5e8f\u5458<\/h3>\n<\/p>\n<p><p><strong>Python\u5199\u7a0b\u5e8f\u5458\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u638c\u63e1Python\u7684\u57fa\u672c\u8bed\u6cd5\u3001\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u3001\u4e86\u89e3\u5e38\u7528\u7684Python\u5e93\u3001\u638c\u63e1\u8c03\u8bd5\u6280\u5de7\u3001\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u3001\u4e0d\u65ad\u7f16\u5199\u548c\u4f18\u5316\u4ee3\u7801\u3002<\/strong> \u5728\u8fd9\u4e9b\u6b65\u9aa4\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u5b83\u76f4\u63a5\u5f71\u54cd\u5230\u5f00\u53d1\u6548\u7387\u548c\u7f16\u7a0b\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5bf9\u4e8e\u521d\u5b66\u8005\u548c\u7ecf\u9a8c\u4e30\u5bcc\u7684\u7a0b\u5e8f\u5458\u90fd\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4e00\u4e2a\u597d\u7684IDE\u4e0d\u4ec5\u63d0\u4f9b\u4ee3\u7801\u7f16\u8f91\u529f\u80fd\uff0c\u8fd8\u96c6\u6210\u4e86\u8c03\u8bd5\u5de5\u5177\u3001\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3001\u4ee3\u7801\u8865\u5168\u3001\u8bed\u6cd5\u9ad8\u4eae\u7b49\u529f\u80fd\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u5e38\u89c1\u7684Python IDE\u5305\u62ecPyCharm\u3001VSCode\u3001Jupyter Notebook\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/h3>\n<\/p>\n<p><p>\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5bf9\u4e8ePython\u7f16\u7a0b\u6765\u8bf4\u975e\u5e38\u91cd\u8981\u3002\u4e00\u4e2a\u597d\u7684IDE\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u9ad8\u7f16\u7801\u6548\u7387\uff0c\u8fd8\u80fd\u5e2e\u52a9\u7a0b\u5e8f\u5458\u66f4\u597d\u5730\u7406\u89e3\u548c\u8c03\u8bd5\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>PyCharm<\/h4>\n<\/p>\n<p><p>PyCharm\u662f\u7531JetBr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns\u5f00\u53d1\u7684\u4e00\u6b3e\u4e13\u4e1a\u7ea7Python IDE\uff0c\u5177\u6709\u5f3a\u5927\u7684\u4ee3\u7801\u5206\u6790\u529f\u80fd\u548c\u667a\u80fd\u4ee3\u7801\u8865\u5168\u529f\u80fd\u3002PyCharm\u652f\u6301\u591a\u79cd\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u5982Git\u3001Mercurial\u3001Subversion\u7b49\uff0c\u8fd8\u96c6\u6210\u4e86\u8c03\u8bd5\u5668\u548c\u6d4b\u8bd5\u5de5\u5177\u3002\u5bf9\u4e8e\u9700\u8981\u5f00\u53d1\u590d\u6742\u9879\u76ee\u7684\u7a0b\u5e8f\u5458\uff0cPyCharm\u662f\u4e00\u4e2a\u975e\u5e38\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h4>Visual Studio Code (VSCode)<\/h4>\n<\/p>\n<p><p>VSCode\u662f\u7531\u5fae\u8f6f\u5f00\u53d1\u7684\u4e00\u6b3e\u5f00\u6e90\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5305\u62ecPython\u3002\u901a\u8fc7\u5b89\u88c5Python\u6269\u5c55\uff0cVSCode\u53ef\u4ee5\u63d0\u4f9b\u7c7b\u4f3cIDE\u7684\u529f\u80fd\uff0c\u5982\u4ee3\u7801\u8865\u5168\u3001\u8c03\u8bd5\u3001Linting\u7b49\u3002VSCode\u7684\u8f7b\u91cf\u7ea7\u548c\u9ad8\u5ea6\u53ef\u5b9a\u5236\u5316\u4f7f\u5176\u6210\u4e3a\u8bb8\u591a\u5f00\u53d1\u8005\u7684\u9996\u9009\u3002<\/p>\n<\/p>\n<p><h4>Jupyter Notebook<\/h4>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u79cd\u4ea4\u4e92\u5f0f\u7684\u8ba1\u7b97\u73af\u5883\uff0c\u5e7f\u6cdb\u7528\u4e8e\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u9886\u57df\u3002\u5b83\u5141\u8bb8\u7528\u6237\u5728\u4e00\u4e2a\u6587\u6863\u4e2d\u7f16\u5199\u548c\u6267\u884c\u4ee3\u7801\uff0c\u5e76\u53ef\u89c6\u5316\u8f93\u51fa\u7ed3\u679c\u3002\u5bf9\u4e8e\u9700\u8981\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u7684\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0cJupyter Notebook\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u638c\u63e1Python\u7684\u57fa\u672c\u8bed\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u597dIDE\u4e4b\u540e\uff0c\u63a5\u4e0b\u6765\u9700\u8981\u638c\u63e1Python\u7684\u57fa\u672c\u8bed\u6cd5\u3002\u8fd9\u662f\u6210\u4e3a\u4e00\u540dPython\u7a0b\u5e8f\u5458\u7684\u57fa\u7840\u3002<\/p>\n<\/p>\n<p><h4>\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>Python\u652f\u6301\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u5178\u7b49\u3002\u4e86\u89e3\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\u662f\u7f16\u5199Python\u4ee3\u7801\u7684\u57fa\u7840\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u53d8\u91cf<\/p>\n<p>a = 10        # \u6574\u6570<\/p>\n<p>b = 3.14      # \u6d6e\u70b9\u6570<\/p>\n<p>c = &quot;Hello&quot;   # \u5b57\u7b26\u4e32<\/p>\n<p>d = [1, 2, 3] # \u5217\u8868<\/p>\n<p>e = (4, 5, 6) # \u5143\u7ec4<\/p>\n<p>f = {&#39;key&#39;: &#39;value&#39;} # \u5b57\u5178<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u63a7\u5236\u7ed3\u6784<\/h4>\n<\/p>\n<p><p>\u63a7\u5236\u7ed3\u6784\u5305\u62ec\u6761\u4ef6\u8bed\u53e5\u548c\u5faa\u73af\u8bed\u53e5\u3002\u5728Python\u4e2d\uff0c\u5e38\u7528\u7684\u63a7\u5236\u7ed3\u6784\u6709if\u8bed\u53e5\u3001for\u5faa\u73af\u548cwhile\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6761\u4ef6\u8bed\u53e5<\/p>\n<p>if a &gt; b:<\/p>\n<p>    print(&quot;a is greater than b&quot;)<\/p>\n<p>elif a == b:<\/p>\n<p>    print(&quot;a is equal to b&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;a is less than b&quot;)<\/p>\n<h2><strong>for\u5faa\u73af<\/strong><\/h2>\n<p>for i in range(5):<\/p>\n<p>    print(i)<\/p>\n<h2><strong>while\u5faa\u73af<\/strong><\/h2>\n<p>count = 0<\/p>\n<p>while count &lt; 5:<\/p>\n<p>    print(count)<\/p>\n<p>    count += 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u51fd\u6570\u548c\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u662f\u7ec4\u7ec7\u4ee3\u7801\u7684\u57fa\u672c\u5355\u5143\uff0c\u901a\u8fc7\u5b9a\u4e49\u51fd\u6570\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u548c\u53ef\u8bfb\u6027\u3002Python\u8fd8\u652f\u6301\u5c06\u4ee3\u7801\u7ec4\u7ec7\u5230\u6a21\u5757\u4e2d\uff0c\u4ee5\u4fbf\u8fdb\u884c\u66f4\u597d\u7684\u7ba1\u7406\u548c\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u51fd\u6570<\/p>\n<p>def add(x, y):<\/p>\n<p>    return x + y<\/p>\n<h2><strong>\u8c03\u7528\u51fd\u6570<\/strong><\/h2>\n<p>result = add(3, 5)<\/p>\n<p>print(result)<\/p>\n<h2><strong>\u5bfc\u5165\u6a21\u5757<\/strong><\/h2>\n<p>import math<\/p>\n<p>print(math.sqrt(16))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b<\/h3>\n<\/p>\n<p><p>\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08OOP\uff09\u662fPython\u7f16\u7a0b\u7684\u4e00\u4e2a\u91cd\u8981\u6982\u5ff5\uff0c\u901a\u8fc7\u5b66\u4e60OOP\u53ef\u4ee5\u66f4\u597d\u5730\u7ec4\u7ec7\u548c\u7ba1\u7406\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>\u7c7b\u548c\u5bf9\u8c61<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u7c7b\u662f\u521b\u5efa\u5bf9\u8c61\u7684\u84dd\u56fe\uff0c\u901a\u8fc7\u5b9a\u4e49\u7c7b\u53ef\u4ee5\u521b\u5efa\u591a\u4e2a\u5b9e\u4f8b\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u7c7b<\/p>\n<p>class Dog:<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        self.name = name<\/p>\n<p>        self.age = age<\/p>\n<p>    def bark(self):<\/p>\n<p>        print(f&quot;{self.name} is barking&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5bf9\u8c61<\/strong><\/h2>\n<p>dog1 = Dog(&quot;Buddy&quot;, 3)<\/p>\n<p>dog2 = Dog(&quot;Lucy&quot;, 2)<\/p>\n<h2><strong>\u8c03\u7528\u65b9\u6cd5<\/strong><\/h2>\n<p>dog1.bark()<\/p>\n<p>dog2.bark()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u7ee7\u627f\u548c\u591a\u6001<\/h4>\n<\/p>\n<p><p>\u7ee7\u627f\u662fOOP\u7684\u91cd\u8981\u7279\u6027\uff0c\u901a\u8fc7\u7ee7\u627f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7c7b\uff0c\u8be5\u7c7b\u7ee7\u627f\u4e86\u7236\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u591a\u6001\u662f\u6307\u4e0d\u540c\u5bf9\u8c61\u53ef\u4ee5\u8c03\u7528\u76f8\u540c\u7684\u65b9\u6cd5\uff0c\u5177\u4f53\u6267\u884c\u7684\u64cd\u4f5c\u53ef\u80fd\u4e0d\u540c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u7236\u7c7b<\/p>\n<p>class Animal:<\/p>\n<p>    def __init__(self, name):<\/p>\n<p>        self.name = name<\/p>\n<p>    def speak(self):<\/p>\n<p>        raise NotImplementedError(&quot;Subclasses must implement this method&quot;)<\/p>\n<h2><strong>\u5b9a\u4e49\u5b50\u7c7b<\/strong><\/h2>\n<p>class Cat(Animal):<\/p>\n<p>    def speak(self):<\/p>\n<p>        return f&quot;{self.name} says Meow&quot;<\/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<h2><strong>\u521b\u5efa\u5bf9\u8c61<\/strong><\/h2>\n<p>cat = Cat(&quot;Whiskers&quot;)<\/p>\n<p>dog = Dog(&quot;Buddy&quot;)<\/p>\n<h2><strong>\u8c03\u7528\u65b9\u6cd5<\/strong><\/h2>\n<p>print(cat.speak())<\/p>\n<p>print(dog.speak())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4e86\u89e3\u5e38\u7528\u7684Python\u5e93<\/h3>\n<\/p>\n<p><p>Python\u62e5\u6709\u4e30\u5bcc\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7a0b\u5e8f\u5458\u5feb\u901f\u5b9e\u73b0\u5404\u79cd\u529f\u80fd\u3002\u4e86\u89e3\u548c\u638c\u63e1\u4e00\u4e9b\u5e38\u7528\u7684Python\u5e93\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<p><h4>NumPy<\/h4>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u5e93\uff0c\u63d0\u4f9b\u4e86\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u5404\u79cd\u6570\u5b66\u51fd\u6570\u3002\u5b83\u662f\u8bb8\u591a\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60\u5e93\u7684\u57fa\u7840\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([1, 2, 3, 4, 5])<\/p>\n<p>print(array)<\/p>\n<h2><strong>\u6570\u7ec4\u8fd0\u7b97<\/strong><\/h2>\n<p>print(array + 10)<\/p>\n<p>print(np.mean(array))<\/p>\n<p>print(np.sum(array))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>Pandas<\/h4>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u64cd\u4f5c\u548c\u5206\u6790\u7684\u5e93\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u5206\u6790\u5de5\u5177\u3002\u901a\u8fc7Pandas\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u3001\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u6846<\/strong><\/h2>\n<p>data = {&#39;Name&#39;: [&#39;Tom&#39;, &#39;Jerry&#39;, &#39;Mickey&#39;],<\/p>\n<p>        &#39;Age&#39;: [25, 30, 22]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>print(df)<\/p>\n<h2><strong>\u6570\u636e\u64cd\u4f5c<\/strong><\/h2>\n<p>print(df[&#39;Age&#39;].mean())<\/p>\n<p>print(df[df[&#39;Age&#39;] &gt; 25])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>Matplotlib<\/h4>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u7684\u5e93\uff0c\u53ef\u4ee5\u751f\u6210\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5982\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u6563\u70b9\u56fe\u7b49\u3002\u901a\u8fc7Matplotlib\u53ef\u4ee5\u5c06\u6570\u636e\u4ee5\u76f4\u89c2\u7684\u65b9\u5f0f\u5c55\u793a\u51fa\u6765\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e<\/strong><\/h2>\n<p>x = [1, 2, 3, 4, 5]<\/p>\n<p>y = [2, 3, 5, 7, 11]<\/p>\n<h2><strong>\u7ed8\u5236\u6298\u7ebf\u56fe<\/strong><\/h2>\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;Line Plot&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>Scikit-learn<\/h4>\n<\/p>\n<p><p>Scikit-learn\u662f\u4e00\u4e2a\u7528\u4e8e\u673a\u5668\u5b66\u4e60\u7684\u5e93\uff0c\u63d0\u4f9b\u4e86\u5404\u79cd\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u548c\u5de5\u5177\u3002\u901a\u8fc7Scikit-learn\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\u3001\u6a21\u578b\u8bad\u7ec3\u548c\u8bc4\u4f30\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.datasets import load_iris<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<p>from sklearn.metrics import accuracy_score<\/p>\n<h2><strong>\u52a0\u8f7d\u6570\u636e\u96c6<\/strong><\/h2>\n<p>data = load_iris()<\/p>\n<p>X = data.data<\/p>\n<p>y = data.target<\/p>\n<h2><strong>\u62c6\u5206\u6570\u636e\u96c6<\/strong><\/h2>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model = RandomForestClassifier()<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u9884\u6d4b<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<h2><strong>\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&quot;Accuracy: {accuracy}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u638c\u63e1\u8c03\u8bd5\u6280\u5de7<\/h3>\n<\/p>\n<p><p>\u8c03\u8bd5\u662f\u7f16\u7a0b\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u907f\u514d\u7684\u4e00\u90e8\u5206\uff0c\u638c\u63e1\u8c03\u8bd5\u6280\u5de7\u53ef\u4ee5\u5e2e\u52a9\u7a0b\u5e8f\u5458\u5feb\u901f\u5b9a\u4f4d\u548c\u4fee\u590d\u4ee3\u7801\u4e2d\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528print()\u8c03\u8bd5<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6700\u7b80\u5355\u7684\u8c03\u8bd5\u65b9\u6cd5\u662f\u4f7f\u7528print()\u51fd\u6570\u6253\u5370\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u6267\u884c\u72b6\u6001\u3002\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u7b80\u5355\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u6548\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(x, y):<\/p>\n<p>    result = x + y<\/p>\n<p>    print(f&quot;Adding {x} and {y} gives {result}&quot;)<\/p>\n<p>    return result<\/p>\n<p>add(3, 5)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4f7f\u7528\u65ad\u70b9\u8c03\u8bd5<\/h4>\n<\/p>\n<p><p>\u5927\u591a\u6570IDE\u90fd\u63d0\u4f9b\u4e86\u65ad\u70b9\u8c03\u8bd5\u529f\u80fd\uff0c\u7a0b\u5e8f\u5458\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u7a0b\u5e8f\u6267\u884c\u5230\u65ad\u70b9\u65f6\u4f1a\u6682\u505c\uff0c\u5141\u8bb8\u7a0b\u5e8f\u5458\u68c0\u67e5\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u6267\u884c\u72b6\u6001\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u7ec6\u81f4\u5730\u8c03\u8bd5\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528\u8c03\u8bd5\u5668<\/h4>\n<\/p>\n<p><p>Python\u5185\u7f6e\u4e86\u4e00\u4e2a\u8c03\u8bd5\u5668\uff0c\u79f0\u4e3apdb\u3002\u901a\u8fc7\u5728\u4ee3\u7801\u4e2d\u63d2\u5165<code>import pdb; pdb.set_trace()<\/code>\uff0c\u7a0b\u5e8f\u6267\u884c\u5230\u8be5\u884c\u65f6\u4f1a\u8fdb\u5165\u8c03\u8bd5\u6a21\u5f0f\uff0c\u7a0b\u5e8f\u5458\u53ef\u4ee5\u901a\u8fc7\u8c03\u8bd5\u5668\u547d\u4ee4\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(x, y):<\/p>\n<p>    import pdb; pdb.set_trace()<\/p>\n<p>    result = x + y<\/p>\n<p>    return result<\/p>\n<p>add(3, 5)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee<\/h3>\n<\/p>\n<p><p>\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u662f\u63d0\u9ad8\u7f16\u7a0b\u6280\u80fd\u548c\u79ef\u7d2f\u5b9e\u9645\u7ecf\u9a8c\u7684\u4e00\u4e2a\u91cd\u8981\u9014\u5f84\u3002\u901a\u8fc7\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\uff0c\u53ef\u4ee5\u63a5\u89e6\u5230\u66f4\u591a\u7684\u5b9e\u9645\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u4e0e\u5176\u4ed6\u5f00\u53d1\u8005\u4ea4\u6d41\u548c\u5408\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>\u5bfb\u627e\u5f00\u6e90\u9879\u76ee<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7GitHub\u3001GitLab\u7b49\u5e73\u53f0\u5bfb\u627e\u611f\u5174\u8da3\u7684\u5f00\u6e90\u9879\u76ee\uff0c\u4e86\u89e3\u9879\u76ee\u7684\u80cc\u666f\u548c\u9700\u6c42\uff0c\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h4>\u63d0\u4ea4\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u5728\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u63d0\u4ea4\u4ee3\u7801\u8d21\u732e\u81ea\u5df1\u7684\u529b\u91cf\u3002\u5728\u63d0\u4ea4\u4ee3\u7801\u4e4b\u524d\uff0c\u9700\u8981\u4ed4\u7ec6\u9605\u8bfb\u9879\u76ee\u7684\u8d21\u732e\u6307\u5357\uff0c\u6309\u7167\u89c4\u8303\u8fdb\u884c\u4ee3\u7801\u7f16\u5199\u548c\u63d0\u4ea4\u3002<\/p>\n<\/p>\n<p><h4>\u53c2\u4e0e\u8ba8\u8bba<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u53c2\u4e0e\u9879\u76ee\u7684\u8ba8\u8bba\uff0c\u53ef\u4ee5\u4e86\u89e3\u9879\u76ee\u7684\u8fdb\u5c55\u548c\u95ee\u9898\uff0c\u63d0\u51fa\u81ea\u5df1\u7684\u610f\u89c1\u548c\u5efa\u8bae\u3002\u901a\u8fc7\u4e0e\u5176\u4ed6\u5f00\u53d1\u8005\u7684\u4ea4\u6d41\uff0c\u53ef\u4ee5\u5b66\u4e60\u5230\u66f4\u591a\u7684\u7f16\u7a0b\u6280\u5de7\u548c\u7ecf\u9a8c\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4e0d\u65ad\u7f16\u5199\u548c\u4f18\u5316\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u7f16\u5199\u4ee3\u7801\u662f\u63d0\u9ad8\u7f16\u7a0b\u6280\u80fd\u7684\u6700\u6709\u6548\u65b9\u6cd5\uff0c\u901a\u8fc7\u4e0d\u65ad\u7f16\u5199\u548c\u4f18\u5316\u4ee3\u7801\uff0c\u53ef\u4ee5\u79ef\u7d2f\u66f4\u591a\u7684\u7ecf\u9a8c\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><h4>\u7f16\u5199\u5c0f\u9879\u76ee<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u7f16\u5199\u5c0f\u9879\u76ee\uff0c\u53ef\u4ee5\u5b9e\u8df5\u6240\u5b66\u7684\u77e5\u8bc6\uff0c\u5e76\u9010\u6b65\u63d0\u9ad8\u7f16\u7a0b\u6280\u80fd\u3002\u53ef\u4ee5\u9009\u62e9\u4e00\u4e9b\u611f\u5174\u8da3\u7684\u4e3b\u9898\uff0c\u5982\u6570\u636e\u5206\u6790\u3001\u7f51\u9875\u5f00\u53d1\u3001\u81ea\u52a8\u5316\u811a\u672c\u7b49\uff0c\u7f16\u5199\u5c0f\u9879\u76ee\u8fdb\u884c\u7ec3\u4e60\u3002<\/p>\n<\/p>\n<p><h4>\u4ee3\u7801\u8bc4\u5ba1<\/h4>\n<\/p>\n<p><p>\u4ee3\u7801\u8bc4\u5ba1\u662f\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u548c\u7f16\u7a0b\u6280\u80fd\u7684\u91cd\u8981\u9014\u5f84\u3002\u901a\u8fc7\u4e0e\u5176\u4ed6\u5f00\u53d1\u8005\u8fdb\u884c\u4ee3\u7801\u8bc4\u5ba1\uff0c\u53ef\u4ee5\u53d1\u73b0\u4ee3\u7801\u4e2d\u7684\u95ee\u9898\u548c\u4e0d\u8db3\uff0c\u5e76\u63d0\u51fa\u6539\u8fdb\u5efa\u8bae\u3002<\/p>\n<\/p>\n<p><h4>\u5b66\u4e60\u65b0\u6280\u672f<\/h4>\n<\/p>\n<p><p>\u7f16\u7a0b\u6280\u672f\u4e0d\u65ad\u53d1\u5c55\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u4e0d\u65ad\u5b66\u4e60\u65b0\u6280\u672f\u548c\u5de5\u5177\uff0c\u4fdd\u6301\u6280\u672f\u7684\u66f4\u65b0\u3002\u53ef\u4ee5\u901a\u8fc7\u9605\u8bfb\u6280\u672f\u4e66\u7c4d\u3001\u53c2\u52a0\u6280\u672f\u4f1a\u8bae\u548c\u57f9\u8bad\u3001\u5173\u6ce8\u6280\u672f\u535a\u5ba2\u548c\u793e\u533a\u7b49\u9014\u5f84\uff0c\u5b66\u4e60\u65b0\u6280\u672f\u548c\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u638c\u63e1Python\u7684\u57fa\u672c\u8bed\u6cd5\u3001\u5b66\u4e60\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u3001\u4e86\u89e3\u5e38\u7528\u7684Python\u5e93\u3001\u638c\u63e1\u8c03\u8bd5\u6280\u5de7\u3001\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u3001\u4e0d\u65ad\u7f16\u5199\u548c\u4f18\u5316\u4ee3\u7801\uff0c\u7a0b\u5e8f\u5458\u53ef\u4ee5\u9010\u6b65\u63d0\u9ad8Python\u7f16\u7a0b\u6280\u80fd\uff0c\u6210\u4e3a\u4e00\u540d\u4f18\u79c0\u7684Python\u7a0b\u5e8f\u5458\u3002\u65e0\u8bba\u662f\u521d\u5b66\u8005\u8fd8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u7a0b\u5e8f\u5458\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u63d0\u5347\u81ea\u5df1\u7684\u7f16\u7a0b\u6c34\u5e73\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5f00\u59cb\u5b66\u4e60Python\u7f16\u7a0b\uff1f<\/strong><br \/>\u5b66\u4e60Python\u7f16\u7a0b\u7684\u7b2c\u4e00\u6b65\u662f\u9009\u62e9\u5408\u9002\u7684\u5b66\u4e60\u8d44\u6e90\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u7ebf\u8bfe\u7a0b\u3001\u4e66\u7c4d\u6216\u89c6\u9891\u6559\u7a0b\u5165\u624b\u3002\u63a8\u8350\u7684\u5728\u7ebf\u5e73\u53f0\u5305\u62ecCoursera\u3001edX\u548cCodecademy\u7b49\u3002\u6b64\u5916\uff0c\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee\u548c\u7f16\u7a0b\u793e\u533a\u4e5f\u80fd\u5e2e\u52a9\u4f60\u66f4\u5feb\u5730\u638c\u63e1Python\u3002<\/p>\n<p><strong>Python\u7f16\u7a0b\u9700\u8981\u54ea\u4e9b\u57fa\u7840\u77e5\u8bc6\uff1f<\/strong><br \/>\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\uff0c\u638c\u63e1\u57fa\u672c\u7684\u7f16\u7a0b\u6982\u5ff5\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u8fd9\u4e9b\u6982\u5ff5\u5305\u62ec\u53d8\u91cf\u3001\u6570\u636e\u7c7b\u578b\u3001\u63a7\u5236\u7ed3\u6784\uff08\u5982\u5faa\u73af\u548c\u6761\u4ef6\u8bed\u53e5\uff09\u3001\u51fd\u6570\u4ee5\u53ca\u57fa\u672c\u7684\u8f93\u5165\u8f93\u51fa\u64cd\u4f5c\u3002\u4e86\u89e3\u8fd9\u4e9b\u57fa\u7840\u77e5\u8bc6\u540e\uff0c\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u7406\u89e3Python\u7684\u8bed\u6cd5\u548c\u7279\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u63d0\u5347\u81ea\u5df1\u7684Python\u7f16\u7a0b\u6280\u80fd\uff1f<\/strong><br \/>\u63d0\u5347Python\u7f16\u7a0b\u6280\u80fd\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u3002\u53c2\u4e0e\u5b9e\u9645\u9879\u76ee\u662f\u975e\u5e38\u6709\u6548\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u5b9e\u8df5\u6765\u5de9\u56fa\u6240\u5b66\u77e5\u8bc6\u3002\u6b64\u5916\uff0c\u5b66\u4e60Python\u7684\u9ad8\u7ea7\u7279\u6027\uff0c\u5982\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u3001\u5f02\u5e38\u5904\u7406\u548c\u6a21\u5757\u5316\u7f16\u7a0b\uff0c\u4e5f\u80fd\u5e2e\u52a9\u4f60\u6210\u4e3a\u4e00\u540d\u66f4\u51fa\u8272\u7684\u5f00\u53d1\u8005\u3002\u540c\u65f6\uff0c\u5b9a\u671f\u9605\u8bfb\u6280\u672f\u535a\u5ba2\u548c\u53c2\u4e0e\u7f16\u7a0b\u6311\u6218\u8d5b\u4e5f\u662f\u63d0\u5347\u6280\u80fd\u7684\u597d\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"PYTHON\u5982\u4f55\u5199\u7a0b\u5e8f\u5458 Python\u5199\u7a0b\u5e8f\u5458\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u638c\u63e1Python\u7684 [&hellip;]","protected":false},"author":3,"featured_media":1076379,"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\/1076374"}],"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=1076374"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076374\/revisions"}],"predecessor-version":[{"id":1076381,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076374\/revisions\/1076381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1076379"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1076374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1076374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1076374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}