{"id":1060243,"date":"2024-12-31T15:32:10","date_gmt":"2024-12-31T07:32:10","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1060243.html"},"modified":"2024-12-31T15:32:19","modified_gmt":"2024-12-31T07:32:19","slug":"python%e4%bb%a3%e7%a0%81%e8%bf%90%e8%a1%8c%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1060243.html","title":{"rendered":"python\u4ee3\u7801\u8fd0\u884c\u8bed\u6cd5\u9519\u8bef\u5982\u4f55\u4fee\u6539"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/d5214999-6f82-4805-a062-b8fa3a6e763c.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u4ee3\u7801\u8fd0\u884c\u8bed\u6cd5\u9519\u8bef\u5982\u4f55\u4fee\u6539\" \/><\/p>\n<p><p> <strong>Python\u4ee3\u7801\u8fd0\u884c\u8bed\u6cd5\u9519\u8bef\u7684\u4fee\u6539\u65b9\u6cd5\u5305\u62ec\uff1a\u68c0\u67e5\u62fc\u5199\u9519\u8bef\u3001\u786e\u4fdd\u6b63\u786e\u7684\u7f29\u8fdb\u3001\u4f7f\u7528\u6b63\u786e\u7684\u62ec\u53f7\u548c\u5f15\u53f7\u3001\u9a8c\u8bc1\u53d8\u91cf\u547d\u540d\u89c4\u5219\u3001\u786e\u4fdd\u6b63\u786e\u7684\u51fd\u6570\u8c03\u7528\u7b49<\/strong>\u3002\u5176\u4e2d\uff0c\u786e\u4fdd\u6b63\u786e\u7684\u7f29\u8fdb\u662fPython\u7f16\u7a0b\u4e2d\u5c24\u4e3a\u5173\u952e\u7684\u4e00\u70b9\uff0c\u56e0\u4e3aPython\u4f7f\u7528\u7f29\u8fdb\u6765\u8868\u793a\u4ee3\u7801\u5757\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><p>\u7f29\u8fdb\u9519\u8bef\u662fPython\u521d\u5b66\u8005\u6700\u5e38\u89c1\u7684\u95ee\u9898\u4e4b\u4e00\u3002Python\u4f7f\u7528\u7f29\u8fdb\u6765\u8868\u793a\u4ee3\u7801\u5757\uff0c\u5982\u5faa\u73af\u3001\u6761\u4ef6\u8bed\u53e5\u3001\u51fd\u6570\u5b9a\u4e49\u7b49\u3002\u5982\u679c\u7f29\u8fdb\u4e0d\u4e00\u81f4\uff0c\u5c31\u4f1a\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u5728\u7f16\u5199if\u8bed\u53e5\u65f6\uff0c\u6761\u4ef6\u6ee1\u8db3\u7684\u4ee3\u7801\u5757\u5fc5\u987b\u6b63\u786e\u7f29\u8fdb\uff0c\u5426\u5219\u5c06\u5f15\u53d1IndentationError\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6b63\u786e\u7f29\u8fdb\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if True:<\/p>\n<p>    print(&quot;This is correctly indented&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e00\u3001\u68c0\u67e5\u62fc\u5199\u9519\u8bef<\/h3>\n<\/p>\n<p><p>\u62fc\u5199\u9519\u8bef\u662f\u5bfc\u81f4Python\u4ee3\u7801\u51fa\u73b0\u8bed\u6cd5\u9519\u8bef\u7684\u5e38\u89c1\u539f\u56e0\u4e4b\u4e00\u3002Python\u5bf9\u5927\u5c0f\u5199\u654f\u611f\uff0c\u56e0\u6b64\u53d8\u91cf\u3001\u51fd\u6570\u540d\u5fc5\u987b\u62fc\u5199\u6b63\u786e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5173\u952e\u5b57\u548c\u5185\u7f6e\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u5173\u952e\u5b57\u548c\u5185\u7f6e\u51fd\u6570\u62fc\u5199\u6b63\u786e\u3002\u4f8b\u5982\uff0c\u4f7f\u7528print\u51fd\u6570\u65f6\uff0c\u5982\u679c\u62fc\u5199\u9519\u8bef\u5c31\u4f1a\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u62fc\u5199<\/p>\n<p>pritn(&quot;Hello, World!&quot;)<\/p>\n<h2><strong>\u6b63\u786e\u7684\u62fc\u5199<\/strong><\/h2>\n<p>print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u53d8\u91cf\u548c\u51fd\u6570\u540d<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u53d8\u91cf\u548c\u51fd\u6570\u540d\u62fc\u5199\u4e00\u81f4\u3002\u5982\u679c\u5728\u5b9a\u4e49\u53d8\u91cf\u6216\u51fd\u6570\u65f6\u62fc\u5199\u9519\u8bef\uff0c\u5728\u4f7f\u7528\u65f6\u4e5f\u4f1a\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u53d8\u91cf<\/p>\n<p>my_var = 10<\/p>\n<h2><strong>\u9519\u8bef\u7684\u62fc\u5199<\/strong><\/h2>\n<p>print(myvar)<\/p>\n<h2><strong>\u6b63\u786e\u7684\u62fc\u5199<\/strong><\/h2>\n<p>print(my_var)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u786e\u4fdd\u6b63\u786e\u7684\u7f29\u8fdb<\/h3>\n<\/p>\n<p><p>Python\u4f7f\u7528\u7f29\u8fdb\u8868\u793a\u4ee3\u7801\u5757\u7684\u5f00\u59cb\u548c\u7ed3\u675f\uff0c\u56e0\u6b64\u7f29\u8fdb\u5fc5\u987b\u4e00\u81f4\u3002\u5e38\u89c1\u7684\u7f29\u8fdb\u9519\u8bef\u5305\u62ec\u7f29\u8fdb\u4e0d\u4e00\u81f4\u6216\u7f29\u8fdb\u5c42\u6b21\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7f29\u8fdb\u4e0d\u4e00\u81f4<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">if True:<\/p>\n<p>print(&quot;This is incorrectly indented&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u4f1a\u5bfc\u81f4IndentationError\uff0c\u56e0\u4e3aprint\u8bed\u53e5\u6ca1\u6709\u6b63\u786e\u7f29\u8fdb\u3002\u6b63\u786e\u7684\u5199\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if True:<\/p>\n<p>    print(&quot;This is correctly indented&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7f29\u8fdb\u5c42\u6b21\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u591a\u5c42\u5d4c\u5957\u7684\u4ee3\u7801\u5757\u4f1a\u5bfc\u81f4\u7f29\u8fdb\u5c42\u6b21\u9519\u8bef\u3002\u786e\u4fdd\u6bcf\u4e00\u5c42\u7684\u7f29\u8fdb\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(5):<\/p>\n<p>    if i % 2 == 0:<\/p>\n<p>        print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u6b63\u786e\u7684\u62ec\u53f7\u548c\u5f15\u53f7<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u62ec\u53f7\u548c\u5f15\u53f7\u5fc5\u987b\u6210\u5bf9\u51fa\u73b0\uff0c\u5426\u5219\u4f1a\u5f15\u53d1\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u62ec\u53f7<\/h4>\n<\/p>\n<p><p>\u62ec\u53f7\u5305\u62ec\u5706\u62ec\u53f7()\u3001\u65b9\u62ec\u53f7[]\u548c\u82b1\u62ec\u53f7{}\uff0c\u4f7f\u7528\u65f6\u5fc5\u987b\u6210\u5bf9\u51fa\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u5199\u6cd5<\/p>\n<p>my_list = [1, 2, 3, 4, 5<\/p>\n<h2><strong>\u6b63\u786e\u7684\u5199\u6cd5<\/strong><\/h2>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5f15\u53f7<\/h4>\n<\/p>\n<p><p>\u5f15\u53f7\u5305\u62ec\u5355\u5f15\u53f7&#39;&#39;\u548c\u53cc\u5f15\u53f7&quot;&quot;\uff0c\u8868\u793a\u5b57\u7b26\u4e32\u65f6\u5fc5\u987b\u6210\u5bf9\u51fa\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u5199\u6cd5<\/p>\n<p>my_string = &quot;Hello, World!<\/p>\n<h2><strong>\u6b63\u786e\u7684\u5199\u6cd5<\/strong><\/h2>\n<p>my_string = &quot;Hello, World!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u9a8c\u8bc1\u53d8\u91cf\u547d\u540d\u89c4\u5219<\/h3>\n<\/p>\n<p><p>Python\u53d8\u91cf\u547d\u540d\u89c4\u5219\u5305\u62ec\uff1a\u53d8\u91cf\u540d\u5fc5\u987b\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934\u3001\u53d8\u91cf\u540d\u53ea\u80fd\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\uff0c\u4e0d\u80fd\u4f7f\u7528Python\u5173\u952e\u5b57\u4f5c\u4e3a\u53d8\u91cf\u540d\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u53d8\u91cf\u540d\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u5199\u6cd5<\/p>\n<p>1st_var = 10<\/p>\n<h2><strong>\u6b63\u786e\u7684\u5199\u6cd5<\/strong><\/h2>\n<p>first_var = 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u53d8\u91cf\u540d\u53ea\u80fd\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u5199\u6cd5<\/p>\n<p>my-var = 10<\/p>\n<h2><strong>\u6b63\u786e\u7684\u5199\u6cd5<\/strong><\/h2>\n<p>my_var = 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4e0d\u80fd\u4f7f\u7528\u5173\u952e\u5b57\u4f5c\u4e3a\u53d8\u91cf\u540d<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u5199\u6cd5<\/p>\n<p>if = 10<\/p>\n<h2><strong>\u6b63\u786e\u7684\u5199\u6cd5<\/strong><\/h2>\n<p>my_if = 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u786e\u4fdd\u6b63\u786e\u7684\u51fd\u6570\u8c03\u7528<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u8c03\u7528\u65f6\u5fc5\u987b\u4f7f\u7528\u6b63\u786e\u7684\u8bed\u6cd5\uff0c\u5305\u62ec\u51fd\u6570\u540d\u3001\u53c2\u6570\u5217\u8868\u548c\u62ec\u53f7\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u51fd\u6570\u540d<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u51fd\u6570\u540d\u62fc\u5199\u6b63\u786e\uff0c\u5e76\u4e14\u51fd\u6570\u5df2\u7ecf\u5b9a\u4e49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u51fd\u6570<\/p>\n<p>def my_function():<\/p>\n<p>    print(&quot;Hello, World!&quot;)<\/p>\n<h2><strong>\u9519\u8bef\u7684\u51fd\u6570\u540d\u62fc\u5199<\/strong><\/h2>\n<p>my_funtion()<\/p>\n<h2><strong>\u6b63\u786e\u7684\u51fd\u6570\u8c03\u7528<\/strong><\/h2>\n<p>my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u53c2\u6570\u5217\u8868\u548c\u62ec\u53f7<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u8c03\u7528\u65f6\u5fc5\u987b\u4f7f\u7528\u6b63\u786e\u7684\u53c2\u6570\u5217\u8868\u548c\u62ec\u53f7\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u51fd\u6570<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<h2><strong>\u9519\u8bef\u7684\u53c2\u6570\u5217\u8868<\/strong><\/h2>\n<p>add(1, )<\/p>\n<h2><strong>\u6b63\u786e\u7684\u51fd\u6570\u8c03\u7528<\/strong><\/h2>\n<p>add(1, 2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u68c0\u67e5\u4ee3\u7801\u903b\u8f91\u548c\u7ed3\u6784<\/h3>\n<\/p>\n<p><p>\u786e\u4fdd\u4ee3\u7801\u903b\u8f91\u548c\u7ed3\u6784\u6b63\u786e\uff0c\u5305\u62ec\u5faa\u73af\u3001\u6761\u4ef6\u8bed\u53e5\u3001\u51fd\u6570\u5b9a\u4e49\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5faa\u73af<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u5faa\u73af\u8bed\u6cd5\u6b63\u786e\uff0c\u5e76\u4e14\u7f29\u8fdb\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u7f29\u8fdb<\/p>\n<p>for i in range(5):<\/p>\n<p>print(i)<\/p>\n<h2><strong>\u6b63\u786e\u7684\u7f29\u8fdb<\/strong><\/h2>\n<p>for i in range(5):<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6761\u4ef6\u8bed\u53e5<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u6761\u4ef6\u8bed\u53e5\u8bed\u6cd5\u6b63\u786e\uff0c\u5e76\u4e14\u7f29\u8fdb\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u7f29\u8fdb<\/p>\n<p>if True:<\/p>\n<p>print(&quot;This is incorrectly indented&quot;)<\/p>\n<h2><strong>\u6b63\u786e\u7684\u7f29\u8fdb<\/strong><\/h2>\n<p>if True:<\/p>\n<p>    print(&quot;This is correctly indented&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u51fd\u6570\u5b9a\u4e49<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u51fd\u6570\u5b9a\u4e49\u8bed\u6cd5\u6b63\u786e\uff0c\u5e76\u4e14\u7f29\u8fdb\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9519\u8bef\u7684\u7f29\u8fdb<\/p>\n<p>def my_function():<\/p>\n<p>print(&quot;Hello, World!&quot;)<\/p>\n<h2><strong>\u6b63\u786e\u7684\u7f29\u8fdb<\/strong><\/h2>\n<p>def my_function():<\/p>\n<p>    print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u548c\u6d4b\u8bd5<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u548c\u6d4b\u8bd5\u53ef\u4ee5\u5e2e\u52a9\u53d1\u73b0\u548c\u4fee\u590d\u8bed\u6cd5\u9519\u8bef\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u8c03\u8bd5\u5de5\u5177\u548c\u6d4b\u8bd5\u6846\u67b6\uff0c\u5982pdb\u3001unittest\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528pdb\u8c03\u8bd5<\/h4>\n<\/p>\n<p><p>pdb\u662fPython\u5185\u7f6e\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u65ad\u70b9\u3001\u67e5\u770b\u53d8\u91cf\u503c\u3001\u5355\u6b65\u6267\u884c\u4ee3\u7801\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb<\/p>\n<p>def my_function():<\/p>\n<p>    a = 10<\/p>\n<p>    b = 20<\/p>\n<p>    pdb.set_trace()  # \u8bbe\u7f6e\u65ad\u70b9<\/p>\n<p>    c = a + b<\/p>\n<p>    print(c)<\/p>\n<p>my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528unittest\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>unittest\u662fPython\u5185\u7f6e\u7684\u6d4b\u8bd5\u6846\u67b6\uff0c\u53ef\u4ee5\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\u3001\u6267\u884c\u6d4b\u8bd5\u3001\u751f\u6210\u6d4b\u8bd5\u62a5\u544a\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>class TestAdd(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__ == &#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>\u516b\u3001\u9605\u8bfb\u548c\u7406\u89e3\u9519\u8bef\u4fe1\u606f<\/h3>\n<\/p>\n<p><p>Python\u89e3\u91ca\u5668\u5728\u4ee3\u7801\u8fd0\u884c\u65f6\u4f1a\u751f\u6210\u9519\u8bef\u4fe1\u606f\uff0c\u5e2e\u52a9\u5b9a\u4f4d\u548c\u4fee\u590d\u8bed\u6cd5\u9519\u8bef\u3002\u9605\u8bfb\u548c\u7406\u89e3\u9519\u8bef\u4fe1\u606f\u662f\u4fee\u590d\u8bed\u6cd5\u9519\u8bef\u7684\u91cd\u8981\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u9519\u8bef\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u9519\u8bef\u4fe1\u606f\u901a\u5e38\u5305\u542b\u9519\u8bef\u7c7b\u578b\uff0c\u5982SyntaxError\u3001IndentationError\u3001NameError\u7b49\u3002\u4e86\u89e3\u9519\u8bef\u7c7b\u578b\u53ef\u4ee5\u5e2e\u52a9\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u9519\u8bef\u4fe1\u606f<\/p>\n<p>SyntaxError: invalid syntax<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u9519\u8bef\u4f4d\u7f6e<\/h4>\n<\/p>\n<p><p>\u9519\u8bef\u4fe1\u606f\u901a\u5e38\u5305\u542b\u9519\u8bef\u4f4d\u7f6e\uff0c\u5305\u62ec\u6587\u4ef6\u540d\u3001\u884c\u53f7\u548c\u4ee3\u7801\u7247\u6bb5\u3002\u6839\u636e\u9519\u8bef\u4f4d\u7f6e\u53ef\u4ee5\u5feb\u901f\u627e\u5230\u51fa\u9519\u7684\u4ee3\u7801\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b\u9519\u8bef\u4fe1\u606f<\/p>\n<p>File &quot;example.py&quot;, line 2<\/p>\n<p>    print(&quot;Hello, World!&quot;<\/p>\n<p>                         ^<\/p>\n<p>SyntaxError: invalid syntax<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u53c2\u8003\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8d44\u6e90<\/h3>\n<\/p>\n<p><p>\u53c2\u8003Python\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8d44\u6e90\u53ef\u4ee5\u5e2e\u52a9\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\u3002\u5b98\u65b9\u6587\u6863\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684\u8bed\u6cd5\u8bf4\u660e\u548c\u793a\u4f8b\uff0c\u793e\u533a\u8d44\u6e90\u5982Stack Overflow\u3001GitHub\u7b49\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u89e3\u51b3\u65b9\u6848\u548c\u8ba8\u8bba\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b98\u65b9\u6587\u6863<\/h4>\n<\/p>\n<p><p>Python\u5b98\u65b9\u6587\u6863\u662f\u5b66\u4e60\u548c\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\u7684\u91cd\u8981\u8d44\u6e90\uff0c\u5305\u542b\u4e86Python\u8bed\u8a00\u7684\u8be6\u7ec6\u8bf4\u660e\u548c\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b98\u65b9\u6587\u6863\u7f51\u5740<\/p>\n<p>https:\/\/docs.python.org\/3\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u793e\u533a\u8d44\u6e90<\/h4>\n<\/p>\n<p><p>\u793e\u533a\u8d44\u6e90\u5982Stack Overflow\u3001GitHub\u7b49\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u89e3\u51b3\u65b9\u6848\u548c\u8ba8\u8bba\uff0c\u53ef\u4ee5\u5e2e\u52a9\u89e3\u51b3\u5b9e\u9645\u7f16\u7a0b\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># Stack Overflow\u7f51\u5740<\/p>\n<p>https:\/\/stackoverflow.com\/<\/p>\n<h2><strong>GitHub\u7f51\u5740<\/strong><\/h2>\n<p>https:\/\/github.com\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u4fee\u590dPython\u4ee3\u7801\u8fd0\u884c\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u9700\u8981\u4ece\u591a\u4e2a\u65b9\u9762\u5165\u624b\uff0c\u5305\u62ec\u68c0\u67e5\u62fc\u5199\u9519\u8bef\u3001\u786e\u4fdd\u6b63\u786e\u7684\u7f29\u8fdb\u3001\u4f7f\u7528\u6b63\u786e\u7684\u62ec\u53f7\u548c\u5f15\u53f7\u3001\u9a8c\u8bc1\u53d8\u91cf\u547d\u540d\u89c4\u5219\u3001\u786e\u4fdd\u6b63\u786e\u7684\u51fd\u6570\u8c03\u7528\u3001\u68c0\u67e5\u4ee3\u7801\u903b\u8f91\u548c\u7ed3\u6784\u3001\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u548c\u6d4b\u8bd5\u3001\u9605\u8bfb\u548c\u7406\u89e3\u9519\u8bef\u4fe1\u606f\u3001\u53c2\u8003\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8d44\u6e90\u7b49\u3002\u901a\u8fc7\u7cfb\u7edf\u5730\u68c0\u67e5\u548c\u4fee\u590d\uff0c\u53ef\u4ee5\u6709\u6548\u89e3\u51b3Python\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u8d28\u91cf\u548c\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5224\u65ad\u6211\u7684Python\u4ee3\u7801\u4e2d\u662f\u5426\u5b58\u5728\u8bed\u6cd5\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u7f16\u5199Python\u4ee3\u7801\u65f6\uff0c\u5982\u679c\u51fa\u73b0\u8bed\u6cd5\u9519\u8bef\uff0c\u901a\u5e38\u4f1a\u6709\u9519\u8bef\u63d0\u793a\u4fe1\u606f\u663e\u793a\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u4e2d\u3002\u8fd9\u4e9b\u4fe1\u606f\u901a\u5e38\u4f1a\u6307\u660e\u9519\u8bef\u7684\u4f4d\u7f6e\u53ca\u5176\u6027\u8d28\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u9605\u8bfb\u8fd9\u4e9b\u63d0\u793a\u6765\u5b9a\u4f4d\u95ee\u9898\u6240\u5728\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u4ee3\u7801\u7f16\u8f91\u5668\uff08\u5982PyCharm\u3001VS Code\u7b49\uff09\u65f6\uff0c\u5b83\u4eec\u901a\u5e38\u4f1a\u5b9e\u65f6\u68c0\u67e5\u4ee3\u7801\u5e76\u63d0\u4f9b\u9519\u8bef\u63d0\u793a\uff0c\u5e2e\u52a9\u4f60\u66f4\u5feb\u5730\u53d1\u73b0\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5e38\u89c1\u7684\u8bed\u6cd5\u9519\u8bef\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5e38\u89c1\u7684\u8bed\u6cd5\u9519\u8bef\u5305\u62ec\uff1a\u7f3a\u5c11\u5192\u53f7\uff08\u4f8b\u5982\u5728\u5b9a\u4e49\u51fd\u6570\u6216\u6761\u4ef6\u8bed\u53e5\u65f6\uff09\u3001\u4e0d\u5339\u914d\u7684\u62ec\u53f7\u6216\u5f15\u53f7\u3001\u4f7f\u7528\u672a\u5b9a\u4e49\u7684\u53d8\u91cf\u3001\u7f29\u8fdb\u9519\u8bef\u7b49\u3002\u8fd9\u4e9b\u9519\u8bef\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\uff0c\u56e0\u6b64\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u4fdd\u6301\u826f\u597d\u7684\u7f29\u8fdb\u548c\u7ed3\u6784\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p><strong>\u5982\u4f55\u6709\u6548\u5730\u8c03\u8bd5\u548c\u4fee\u590dPython\u8bed\u6cd5\u9519\u8bef\uff1f<\/strong><br \/>\u8c03\u8bd5Python\u8bed\u6cd5\u9519\u8bef\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\u3002\u9996\u5148\uff0c\u4ed4\u7ec6\u68c0\u67e5\u9519\u8bef\u4fe1\u606f\u4e2d\u7684\u884c\u53f7\u548c\u9519\u8bef\u7c7b\u578b\uff0c\u5b9a\u4f4d\u95ee\u9898\u3002\u5176\u6b21\uff0c\u5c06\u4ee3\u7801\u5206\u6bb5\u8fd0\u884c\uff0c\u9010\u6b65\u786e\u8ba4\u6bcf\u4e00\u90e8\u5206\u7684\u6b63\u786e\u6027\u3002\u6b64\u5916\uff0c\u5229\u7528\u5728\u7ebfPython\u8bed\u6cd5\u68c0\u67e5\u5de5\u5177\u6216IDE\u7684\u8c03\u8bd5\u529f\u80fd\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5e2e\u52a9\u8bc6\u522b\u5e76\u4fee\u590d\u95ee\u9898\u3002\u5b9e\u8df5\u4e2d\uff0c\u4fdd\u6301\u4ee3\u7801\u6e05\u6670\u3001\u7b80\u6d01\uff0c\u826f\u597d\u7684\u6ce8\u91ca\u548c\u7ed3\u6784\u4e5f\u6709\u52a9\u4e8e\u51cf\u5c11\u9519\u8bef\u7684\u53d1\u751f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4ee3\u7801\u8fd0\u884c\u8bed\u6cd5\u9519\u8bef\u7684\u4fee\u6539\u65b9\u6cd5\u5305\u62ec\uff1a\u68c0\u67e5\u62fc\u5199\u9519\u8bef\u3001\u786e\u4fdd\u6b63\u786e\u7684\u7f29\u8fdb\u3001\u4f7f\u7528\u6b63\u786e\u7684\u62ec\u53f7\u548c\u5f15\u53f7\u3001\u9a8c\u8bc1\u53d8\u91cf\u547d\u540d\u89c4 [&hellip;]","protected":false},"author":3,"featured_media":1060260,"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\/1060243"}],"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=1060243"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1060243\/revisions"}],"predecessor-version":[{"id":1060261,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1060243\/revisions\/1060261"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1060260"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1060243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1060243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1060243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}