{"id":935176,"date":"2024-12-26T18:48:25","date_gmt":"2024-12-26T10:48:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/935176.html"},"modified":"2024-12-26T18:48:27","modified_gmt":"2024-12-26T10:48:27","slug":"python-%e5%a6%82%e4%bd%95%e8%b7%b3%e5%87%ba%e9%80%92%e5%bd%92","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/935176.html","title":{"rendered":"python \u5982\u4f55\u8df3\u51fa\u9012\u5f52"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25071919\/70c59853-c21a-44d8-8d51-dae4d0b5edca.webp\" alt=\"python \u5982\u4f55\u8df3\u51fa\u9012\u5f52\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8df3\u51fa\u9012\u5f52\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u589e\u52a0\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u3001\u4f7f\u7528\u5f02\u5e38\u6355\u83b7\u673a\u5236\u3001\u4f18\u5316\u9012\u5f52\u903b\u8f91\u3001\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6216\u975e\u5c40\u90e8\u53d8\u91cf\u3002<\/strong> \u5176\u4e2d\uff0c\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u7684\u8bbe\u7f6e\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u786e\u4fdd\u9012\u5f52\u51fd\u6570\u5728\u6ee1\u8db3\u67d0\u4e9b\u6761\u4ef6\u65f6\u53ef\u4ee5\u505c\u6b62\u8c03\u7528\u81ea\u8eab\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u6765\u8df3\u51fa\u9012\u5f52\u3002<\/p>\n<\/p>\n<p><p>\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u662f\u6307\u4e00\u4e2a\u660e\u786e\u7684\u7ec8\u6b62\u6761\u4ef6\u3002\u5f53\u9012\u5f52\u51fd\u6570\u8fbe\u5230\u8fd9\u4e2a\u6761\u4ef6\u65f6\uff0c\u4e0d\u518d\u8c03\u7528\u81ea\u8eab\uff0c\u800c\u662f\u8fd4\u56de\u4e00\u4e2a\u7279\u5b9a\u503c\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u907f\u514d\u65e0\u9650\u9012\u5f52\uff0c\u9632\u6b62\u7a0b\u5e8f\u5d29\u6e83\u3002\u4f8b\u5982\uff0c\u5728\u8ba1\u7b97\u9636\u4e58\u7684\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u57fa\u51c6\u6761\u4ef6\u901a\u5e38\u662f\u5f53\u8f93\u5165\u4e3a\u96f6\u65f6\u8fd4\u56de1\u3002\u8fd9\u662f\u56e0\u4e3a0\u7684\u9636\u4e58\u5b9a\u4e49\u4e3a1\u3002\u901a\u8fc7\u8fd9\u79cd\u7b80\u5355\u7684\u57fa\u51c6\u6761\u4ef6\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u786e\u4fdd\u9012\u5f52\u51fd\u6570\u603b\u80fd\u5728\u6709\u9650\u7684\u6b65\u9aa4\u5185\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u9012\u5f52\u57fa\u51c6\u6761\u4ef6<\/p>\n<\/p>\n<p><p>\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u662f\u9012\u5f52\u51fd\u6570\u80fd\u591f\u6b63\u5e38\u7ec8\u6b62\u7684\u5173\u952e\u3002\u5b83\u786e\u4fdd\u9012\u5f52\u4e0d\u4f1a\u65e0\u9650\u8fdb\u884c\uff0c\u4ece\u800c\u907f\u514d\u6808\u6ea2\u51fa\u7b49\u95ee\u9898\u3002\u5728\u7f16\u5199\u9012\u5f52\u51fd\u6570\u65f6\uff0c\u9996\u5148\u9700\u8981\u660e\u786e\u9012\u5f52\u7684\u76ee\u6807\u548c\u7ec8\u6b62\u6761\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>1.1 \u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u7684\u91cd\u8981\u6027<\/h3>\n<\/p>\n<p><p>\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u662f\u4e00\u4e2a\u9012\u5f52\u51fd\u6570\u7684\u6838\u5fc3\u90e8\u5206\u3002\u6ca1\u6709\u57fa\u51c6\u6761\u4ef6\u7684\u9012\u5f52\u51fd\u6570\u5c06\u4f1a\u9677\u5165\u65e0\u9650\u5faa\u73af\uff0c\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002\u57fa\u51c6\u6761\u4ef6\u901a\u5e38\u662f\u4e00\u4e2a\u7b80\u5355\u3001\u660e\u786e\u7684\u5224\u65ad\uff0c\u7528\u4e8e\u7ec8\u6b62\u9012\u5f52\u8c03\u7528\u3002\u4f8b\u5982\uff0c\u5728\u8ba1\u7b97\u6590\u6ce2\u90a3\u5951\u6570\u5217\u65f6\uff0c\u5e38\u7528\u7684\u57fa\u51c6\u6761\u4ef6\u662f\u8f93\u5165\u4e3a0\u62161\u65f6\uff0c\u76f4\u63a5\u8fd4\u56de\u8f93\u5165\u503c\u3002<\/p>\n<\/p>\n<p><h3>1.2 \u5982\u4f55\u8bbe\u7f6e\u9012\u5f52\u57fa\u51c6\u6761\u4ef6<\/h3>\n<\/p>\n<p><p>\u8bbe\u7f6e\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u65f6\uff0c\u9700\u8981\u6839\u636e\u95ee\u9898\u7684\u6027\u8d28\u786e\u5b9a\u5408\u9002\u7684\u7ec8\u6b62\u6761\u4ef6\u3002\u901a\u5e38\uff0c\u57fa\u51c6\u6761\u4ef6\u4e0e\u95ee\u9898\u7684\u8fb9\u754c\u60c5\u51b5\u7d27\u5bc6\u76f8\u5173\u3002\u4f8b\u5982\uff0c\u5728\u5904\u7406\u5b57\u7b26\u4e32\u7684\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u57fa\u51c6\u6761\u4ef6\u53ef\u80fd\u662f\u5b57\u7b26\u4e32\u4e3a\u7a7a\u6216\u53ea\u6709\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def factorial(n):<\/p>\n<p>    if n == 0:<\/p>\n<p>        return 1  # \u57fa\u51c6\u6761\u4ef6<\/p>\n<p>    else:<\/p>\n<p>        return n * factorial(n - 1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>n == 0<\/code>\u662f\u9012\u5f52\u7684\u57fa\u51c6\u6761\u4ef6\uff0c\u786e\u4fdd\u51fd\u6570\u5728<code>n<\/code>\u4e3a\u96f6\u65f6\u505c\u6b62\u9012\u5f52\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5f02\u5e38\u6355\u83b7\u673a\u5236<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5f02\u5e38\u6355\u83b7\u673a\u5236\u6765\u4e2d\u65ad\u9012\u5f52\u3002\u901a\u8fc7\u5f15\u53d1\u5f02\u5e38\uff0c\u53ef\u4ee5\u7acb\u5373\u8df3\u51fa\u5f53\u524d\u7684\u9012\u5f52\u8c03\u7528\u94fe\u3002\u8fd9\u79cd\u65b9\u6cd5\u901a\u5e38\u7528\u4e8e\u5904\u7406\u5f02\u5e38\u60c5\u51b5\uff0c\u800c\u4e0d\u662f\u6b63\u5e38\u7684\u9012\u5f52\u7ec8\u6b62\u3002<\/p>\n<\/p>\n<p><h3>2.1 \u4f7f\u7528\u5f02\u5e38\u6355\u83b7\u4e2d\u65ad\u9012\u5f52<\/h3>\n<\/p>\n<p><p>\u5728\u9012\u5f52\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u9047\u5230\u67d0\u4e9b\u5f02\u5e38\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se<\/code>\u5173\u952e\u5b57\u5f15\u53d1\u5f02\u5e38\uff0c\u5e76\u4f7f\u7528<code>try-except<\/code>\u7ed3\u6784\u6765\u6355\u83b7\u5f02\u5e38\uff0c\u4ece\u800c\u4e2d\u65ad\u9012\u5f52\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u5982\u57fa\u51c6\u6761\u4ef6\u5e38\u7528\uff0c\u4f46\u5728\u5904\u7406\u67d0\u4e9b\u590d\u6742\u9012\u5f52\u95ee\u9898\u65f6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def recursive_function(n):<\/p>\n<p>    try:<\/p>\n<p>        if n &lt; 0:<\/p>\n<p>            raise ValueError(&quot;Negative value encountered&quot;)  # \u5f15\u53d1\u5f02\u5e38<\/p>\n<p>        elif n == 0:<\/p>\n<p>            return 0<\/p>\n<p>        else:<\/p>\n<p>            return n + recursive_function(n - 1)<\/p>\n<p>    except ValueError as e:<\/p>\n<p>        print(e)<\/p>\n<p>        return None<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.2 \u4f18\u52bf\u548c\u5c40\u9650<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u5f02\u5e38\u6355\u83b7\u673a\u5236\u53ef\u4ee5\u5feb\u901f\u4e2d\u65ad\u9012\u5f52\uff0c\u8fd9\u5728\u5904\u7406\u9519\u8bef\u8f93\u5165\u6216\u7279\u6b8a\u6761\u4ef6\u65f6\u975e\u5e38\u6709\u7528\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u9002\u7528\u4e8e\u5e38\u89c4\u7684\u9012\u5f52\u7ec8\u6b62\uff0c\u56e0\u4e3a\u5f02\u5e38\u673a\u5236\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u7684\u6027\u80fd\uff0c\u5e76\u4e14\u4f7f\u4ee3\u7801\u7684\u903b\u8f91\u53d8\u5f97\u590d\u6742\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f18\u5316\u9012\u5f52\u903b\u8f91<\/p>\n<\/p>\n<p><p>\u4f18\u5316\u9012\u5f52\u903b\u8f91\u662f\u63d0\u5347\u9012\u5f52\u6548\u7387\u548c\u907f\u514d\u65e0\u9650\u9012\u5f52\u7684\u4e00\u79cd\u91cd\u8981\u624b\u6bb5\u3002\u901a\u8fc7\u5408\u7406\u8bbe\u8ba1\u9012\u5f52\u51fd\u6570\u7684\u903b\u8f91\uff0c\u53ef\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u9012\u5f52\u8c03\u7528\uff0c\u4ece\u800c\u63d0\u9ad8\u7a0b\u5e8f\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><h3>3.1 \u5c3e\u9012\u5f52\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u5c3e\u9012\u5f52\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u9012\u5f52\u5f62\u5f0f\uff0c\u5176\u4e2d\u9012\u5f52\u8c03\u7528\u662f\u51fd\u6570\u7684\u6700\u540e\u4e00\u6b65\u3002\u8fd9\u79cd\u9012\u5f52\u5f62\u5f0f\u5728\u67d0\u4e9b\u7f16\u7a0b\u8bed\u8a00\u4e2d\u53ef\u4ee5\u901a\u8fc7\u7f16\u8bd1\u5668\u4f18\u5316\u4e3a\u8fed\u4ee3\uff0c\u4ece\u800c\u907f\u514d\u6808\u6ea2\u51fa\u3002\u5728Python\u4e2d\uff0c\u867d\u7136\u6ca1\u6709\u76f4\u63a5\u7684\u5c3e\u9012\u5f52\u4f18\u5316\u673a\u5236\uff0c\u4f46\u901a\u8fc7\u6539\u5199\u9012\u5f52\u51fd\u6570\uff0c\u53ef\u4ee5\u6a21\u62df\u8fd9\u79cd\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def tail_recursive_factorial(n, accumulator=1):<\/p>\n<p>    if n == 0:<\/p>\n<p>        return accumulator<\/p>\n<p>    else:<\/p>\n<p>        return tail_recursive_factorial(n - 1, n * accumulator)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.2 \u51cf\u5c11\u9012\u5f52\u6df1\u5ea6<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u51cf\u5c11\u9012\u5f52\u6df1\u5ea6\uff0c\u53ef\u4ee5\u6709\u6548\u964d\u4f4e\u9012\u5f52\u7684\u590d\u6742\u5ea6\u3002\u4f8b\u5982\uff0c\u5728\u5904\u7406\u6811\u7ed3\u6784\u7684\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u526a\u679d\u6280\u672f\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u9012\u5f52\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6216\u975e\u5c40\u90e8\u53d8\u91cf<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6216\u975e\u5c40\u90e8\u53d8\u91cf\u6765\u63a7\u5236\u9012\u5f52\u7684\u7ec8\u6b62\u6761\u4ef6\u3002\u901a\u8fc7\u5728\u9012\u5f52\u51fd\u6570\u5916\u90e8\u8bbe\u7f6e\u4e00\u4e2a\u6807\u5fd7\u53d8\u91cf\uff0c\u53ef\u4ee5\u52a8\u6001\u63a7\u5236\u9012\u5f52\u7684\u8fdb\u884c\u548c\u7ec8\u6b62\u3002<\/p>\n<\/p>\n<p><h3>4.1 \u4f7f\u7528\u5168\u5c40\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5168\u5c40\u53d8\u91cf\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u5916\u5171\u4eab\u6570\u636e\u3002\u5728\u9012\u5f52\u51fd\u6570\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u5168\u5c40\u53d8\u91cf\u7684\u503c\u6765\u5f71\u54cd\u9012\u5f52\u7684\u6267\u884c\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">stop_recursion = False<\/p>\n<p>def global_controlled_recursion(n):<\/p>\n<p>    global stop_recursion<\/p>\n<p>    if stop_recursion or n == 0:<\/p>\n<p>        return<\/p>\n<p>    print(n)<\/p>\n<p>    if n == 5:<\/p>\n<p>        stop_recursion = True  # \u8bbe\u7f6e\u5168\u5c40\u53d8\u91cf\uff0c\u7ec8\u6b62\u9012\u5f52<\/p>\n<p>    global_controlled_recursion(n - 1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.2 \u4f7f\u7528\u975e\u5c40\u90e8\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u975e\u5c40\u90e8\u53d8\u91cf\u662f\u5728\u5d4c\u5957\u51fd\u6570\u4e2d\u4f7f\u7528\u7684\u53d8\u91cf\uff0c\u53ef\u4ee5\u901a\u8fc7<code>nonlocal<\/code>\u5173\u952e\u5b57\u8fdb\u884c\u58f0\u660e\u548c\u4fee\u6539\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5728\u9012\u5f52\u51fd\u6570\u4e2d\u9700\u8981\u5171\u4eab\u72b6\u6001\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def outer_function():<\/p>\n<p>    stop_recursion = False<\/p>\n<p>    def nonlocal_controlled_recursion(n):<\/p>\n<p>        nonlocal stop_recursion<\/p>\n<p>        if stop_recursion or n == 0:<\/p>\n<p>            return<\/p>\n<p>        print(n)<\/p>\n<p>        if n == 5:<\/p>\n<p>            stop_recursion = True  # \u8bbe\u7f6e\u975e\u5c40\u90e8\u53d8\u91cf\uff0c\u7ec8\u6b62\u9012\u5f52<\/p>\n<p>        nonlocal_controlled_recursion(n - 1)<\/p>\n<p>    nonlocal_controlled_recursion(10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u9012\u5f52\u662f\u4e00\u79cd\u5f3a\u5927\u800c\u7075\u6d3b\u7684\u7f16\u7a0b\u6280\u5de7\uff0c\u4f46\u4e5f\u9700\u8981\u8c28\u614e\u4f7f\u7528\u4ee5\u907f\u514d\u5e38\u89c1\u7684\u9677\u9631\u3002\u901a\u8fc7\u8bbe\u7f6e\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u3001\u4f7f\u7528\u5f02\u5e38\u6355\u83b7\u673a\u5236\u3001\u4f18\u5316\u9012\u5f52\u903b\u8f91\u4ee5\u53ca\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6216\u975e\u5c40\u90e8\u53d8\u91cf\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u63a7\u5236\u9012\u5f52\u7684\u6267\u884c\u548c\u7ec8\u6b62\u3002\u5728\u7f16\u5199\u9012\u5f52\u51fd\u6570\u65f6\uff0c\u9996\u5148\u5e94\u660e\u786e\u9012\u5f52\u7684\u76ee\u6807\u548c\u7ec8\u6b62\u6761\u4ef6\uff0c\u786e\u4fdd\u9012\u5f52\u80fd\u591f\u5728\u5408\u7406\u7684\u6b65\u9aa4\u5185\u7ed3\u675f\uff0c\u4ece\u800c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6709\u6548\u5730\u63a7\u5236\u9012\u5f52\u6df1\u5ea6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u9012\u5f52\u6df1\u5ea6\u662f\u53d7\u5230\u9650\u5236\u7684\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>sys.setrecursionlimit()<\/code>\u6765\u8c03\u6574\u6700\u5927\u9012\u5f52\u6df1\u5ea6\uff0c\u4f46\u8fd9\u5e76\u4e0d\u662f\u89e3\u51b3\u6240\u6709\u95ee\u9898\u7684\u6839\u672c\u65b9\u6cd5\u3002\u5efa\u8bae\u4f18\u5316\u9012\u5f52\u7b97\u6cd5\uff0c\u6bd4\u5982\u4f7f\u7528\u5c3e\u9012\u5f52\u6216\u8fed\u4ee3\u65b9\u6cd5\uff0c\u6765\u907f\u514d\u8d85\u51fa\u9650\u5236\uff0c\u786e\u4fdd\u7a0b\u5e8f\u7a33\u5b9a\u8fd0\u884c\u3002<\/p>\n<p><strong>\u9012\u5f52\u51fd\u6570\u51fa\u9519\u65f6\u5982\u4f55\u5904\u7406\uff1f<\/strong><br \/>\u5982\u679c\u5728\u9012\u5f52\u8fc7\u7a0b\u4e2d\u9047\u5230\u9519\u8bef\uff0c\u6bd4\u5982\u6808\u6ea2\u51fa\u6216\u903b\u8f91\u9519\u8bef\uff0c\u53ef\u4ee5\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u673a\u5236\u6765\u6355\u83b7\u5e76\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\u3002\u901a\u8fc7<code>try...except<\/code>\u8bed\u53e5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u6355\u6349\u5230\u5f02\u5e38\u5e76\u91c7\u53d6\u76f8\u5e94\u7684\u63aa\u65bd\uff0c\u6bd4\u5982\u8fd4\u56de\u4e00\u4e2a\u9ed8\u8ba4\u503c\u6216\u8bb0\u5f55\u9519\u8bef\u65e5\u5fd7\uff0c\u8fd9\u6837\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u907f\u514d\u4f7f\u7528\u9012\u5f52\u7684\u65b9\u6cd5\u6765\u89e3\u51b3\u95ee\u9898\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\uff01\u8bb8\u591a\u95ee\u9898\u53ef\u4ee5\u901a\u8fc7\u8fed\u4ee3\u65b9\u6cd5\u6765\u89e3\u51b3\u3002\u4f7f\u7528\u5faa\u73af\u7ed3\u6784\uff0c\u4f8b\u5982<code>while<\/code>\u6216<code>for<\/code>\uff0c\u53ef\u4ee5\u4ee3\u66ff\u9012\u5f52\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u5982\u6811\u6216\u56fe\u65f6\u3002\u8fed\u4ee3\u65b9\u6cd5\u901a\u5e38\u66f4\u52a0\u9ad8\u6548\uff0c\u4e14\u4e0d\u6613\u9020\u6210\u6808\u6ea2\u51fa\uff0c\u9002\u5408\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8df3\u51fa\u9012\u5f52\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u589e\u52a0\u9012\u5f52\u57fa\u51c6\u6761\u4ef6\u3001\u4f7f\u7528\u5f02\u5e38\u6355\u83b7\u673a\u5236\u3001\u4f18\u5316\u9012\u5f52\u903b\u8f91\u3001\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6216\u975e\u5c40\u90e8\u53d8\u91cf [&hellip;]","protected":false},"author":3,"featured_media":935179,"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\/935176"}],"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=935176"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/935176\/revisions"}],"predecessor-version":[{"id":935181,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/935176\/revisions\/935181"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/935179"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=935176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=935176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=935176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}