{"id":1070680,"date":"2025-01-08T11:00:27","date_gmt":"2025-01-08T03:00:27","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1070680.html"},"modified":"2025-01-08T11:00:29","modified_gmt":"2025-01-08T03:00:29","slug":"python%e4%ba%a4%e4%ba%92%e6%a8%a1%e5%bc%8f%e5%a6%82%e4%bd%95%e5%bc%ba%e5%88%b6%e7%bb%93%e6%9d%9f%e6%97%a0%e9%99%90%e5%be%aa%e7%8e%af-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1070680.html","title":{"rendered":"python\u4ea4\u4e92\u6a21\u5f0f\u5982\u4f55\u5f3a\u5236\u7ed3\u675f\u65e0\u9650\u5faa\u73af"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25101346\/63aa519f-b7a5-44fb-ba90-9eb3030c827d.webp\" alt=\"python\u4ea4\u4e92\u6a21\u5f0f\u5982\u4f55\u5f3a\u5236\u7ed3\u675f\u65e0\u9650\u5faa\u73af\" \/><\/p>\n<p><p> <strong>\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u5f3a\u5236\u7ed3\u675f\u65e0\u9650\u5faa\u73af\uff1a\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C\u3001\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u673a\u5236\u3001\u8bbe\u7f6e\u6761\u4ef6\u9000\u51fa\u5faa\u73af\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>\u5176\u4e2d\uff0c\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C\u662f\u6700\u5e38\u7528\u548c\u76f4\u63a5\u7684\u65b9\u5f0f\u3002<\/strong>\u5f53Python\u811a\u672c\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u8fd0\u884c\u65f6\uff0c\u5982\u679c\u9047\u5230\u65e0\u9650\u5faa\u73af\uff0c\u53ef\u4ee5\u6309\u4e0bCtrl\u952e\u548cC\u952e\u6765\u4e2d\u65ad\u7a0b\u5e8f\u7684\u6267\u884c\u3002\u8fd9\u6837\u53ef\u4ee5\u7acb\u5373\u505c\u6b62\u5faa\u73af\uff0c\u6062\u590d\u5230\u547d\u4ee4\u63d0\u793a\u7b26\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\uff0c\u5e76\u4e14\u64cd\u4f5c\u7b80\u4fbf\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C<\/p>\n<\/p>\n<p><p>\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e2d\uff0c\u5982\u679c\u9047\u5230\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff0c\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C\u6765\u5f3a\u5236\u4e2d\u65ad\u7a0b\u5e8f\u7684\u8fd0\u884c\u3002\u8fd9\u4e2a\u5feb\u6377\u952e\u662f\u4e00\u4e2a\u901a\u7528\u7684\u4e2d\u65ad\u4fe1\u53f7\uff0c\u80fd\u591f\u7acb\u5373\u505c\u6b62\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\uff0c\u5e76\u8fd4\u56de\u5230\u547d\u4ee4\u63d0\u793a\u7b26\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5982\u4f55\u4f7f\u7528Ctrl+C<\/li>\n<\/ol>\n<p><p>\u5f53\u4f60\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u6267\u884c\u4e00\u6bb5\u4ee3\u7801\u65f6\uff0c\u4ee3\u7801\u4f1a\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u8fd0\u884c\u3002\u5982\u679c\u8fd9\u6bb5\u4ee3\u7801\u8fdb\u5165\u4e86\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff0c\u4f60\u53ef\u4ee5\u6309\u4e0bCtrl\u952e\uff0c\u7136\u540e\u540c\u65f6\u6309\u4e0bC\u952e\u3002\u8fd9\u6837\uff0cPython\u89e3\u91ca\u5668\u4f1a\u6355\u6349\u5230\u4e2d\u65ad\u4fe1\u53f7\uff0c\u505c\u6b62\u5f53\u524d\u7684\u8fd0\u884c\uff0c\u5e76\u8fd4\u56de\u5230\u547d\u4ee4\u63d0\u793a\u7b26\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u4f1a\u8fdb\u5165\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    print(&quot;This is an infinite loop&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u4e0d\u65ad\u5730\u6253\u5370&quot;This is an infinite loop&quot;\u3002\u6b64\u65f6\uff0c\u4f60\u53ef\u4ee5\u6309\u4e0bCtrl+C\u6765\u4e2d\u65ad\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u673a\u5236<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u673a\u5236\u6765\u5f3a\u5236\u7ed3\u675f\u65e0\u9650\u5faa\u73af\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528try-except\u8bed\u53e5\u6765\u6355\u6349\u5f02\u5e38\uff0c\u5e76\u5728\u6355\u6349\u5230\u7279\u5b9a\u5f02\u5e38\u65f6\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6355\u6349KeyboardInterrupt\u5f02\u5e38<\/li>\n<\/ol>\n<p><p>\u5f53\u4f60\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u6309\u4e0bCtrl+C\u65f6\uff0cPython\u4f1a\u5f15\u53d1\u4e00\u4e2aKeyboardInterrupt\u5f02\u5e38\u3002\u4f60\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u6355\u6349\u8fd9\u4e2a\u5f02\u5e38\uff0c\u5e76\u5728\u6355\u6349\u5230\u5f02\u5e38\u65f6\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u4f7f\u7528try-except\u8bed\u53e5\u6765\u6355\u6349KeyboardInterrupt\u5f02\u5e38\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    while True:<\/p>\n<p>        print(&quot;This is an infinite loop&quot;)<\/p>\n<p>except KeyboardInterrupt:<\/p>\n<p>    print(&quot;Loop interrupted by user&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u4e0d\u65ad\u5730\u6253\u5370&quot;This is an infinite loop&quot;\u3002\u6b64\u65f6\uff0c\u5982\u679c\u4f60\u6309\u4e0bCtrl+C\uff0c\u4ee3\u7801\u4f1a\u6355\u6349\u5230KeyboardInterrupt\u5f02\u5e38\uff0c\u5e76\u6253\u5370&quot;Loop interrupted by user&quot;\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38<\/li>\n<\/ol>\n<p><p>\u9664\u4e86\u6355\u6349KeyboardInterrupt\u5f02\u5e38\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u5f02\u5e38\u7c7b\uff0c\u5e76\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u5f15\u53d1\u8be5\u5f02\u5e38\u6765\u7ed3\u675f\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b\uff0c\u5e76\u5728\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u65f6\u5f15\u53d1\u8be5\u5f02\u5e38\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class CustomException(Exception):<\/p>\n<p>    pass<\/p>\n<p>try:<\/p>\n<p>    while True:<\/p>\n<p>        user_input = input(&quot;Enter &#39;exit&#39; to stop the loop: &quot;)<\/p>\n<p>        if user_input == &#39;exit&#39;:<\/p>\n<p>            r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se CustomException(&quot;User requested to exit the loop&quot;)<\/p>\n<p>except CustomException as e:<\/p>\n<p>    print(e)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u63d0\u793a\u4f60\u8f93\u5165\u4e00\u4e9b\u5185\u5bb9\u3002\u5982\u679c\u4f60\u8f93\u5165&#39;exit&#39;\uff0c\u4ee3\u7801\u4f1a\u5f15\u53d1CustomException\u5f02\u5e38\uff0c\u5e76\u6253\u5370&quot;User requested to exit the loop&quot;\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u8bbe\u7f6e\u6761\u4ef6\u9000\u51fa\u5faa\u73af<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C\u548c\u5f02\u5e38\u5904\u7406\u673a\u5236\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6761\u4ef6\u6765\u9000\u51fa\u65e0\u9650\u5faa\u73af\u3002\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e9b\u6761\u4ef6\u6765\u5224\u65ad\u662f\u5426\u9700\u8981\u9000\u51fa\u5faa\u73af\uff0c\u5e76\u5728\u6ee1\u8db3\u6761\u4ef6\u65f6\u4f7f\u7528break\u8bed\u53e5\u6765\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528break\u8bed\u53e5<\/li>\n<\/ol>\n<p><p>\u5728Python\u4e2d\uff0cbreak\u8bed\u53e5\u53ef\u4ee5\u7528\u6765\u7acb\u5373\u9000\u51fa\u5f53\u524d\u7684\u5faa\u73af\u3002\u4f60\u53ef\u4ee5\u5728\u5faa\u73af\u4e2d\u8bbe\u7f6e\u4e00\u4e9b\u6761\u4ef6\uff0c\u5f53\u6761\u4ef6\u6ee1\u8db3\u65f6\u4f7f\u7528break\u8bed\u53e5\u6765\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u4f7f\u7528break\u8bed\u53e5\u6765\u9000\u51fa\u65e0\u9650\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">count = 0<\/p>\n<p>while True:<\/p>\n<p>    print(&quot;This is an infinite loop&quot;)<\/p>\n<p>    count += 1<\/p>\n<p>    if count &gt;= 10:<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u6253\u5370&quot;This is an infinite loop&quot;\u5341\u6b21\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf<\/li>\n<\/ol>\n<p><p>\u9664\u4e86\u76f4\u63a5\u5728\u5faa\u73af\u4e2d\u4f7f\u7528break\u8bed\u53e5\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf\u6765\u63a7\u5236\u5faa\u73af\u7684\u9000\u51fa\u3002\u5728\u5faa\u73af\u5f00\u59cb\u4e4b\u524d\uff0c\u5b9a\u4e49\u4e00\u4e2a\u6761\u4ef6\u53d8\u91cf\uff0c\u5e76\u5728\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u65f6\u4fee\u6539\u8be5\u53d8\u91cf\u7684\u503c\uff0c\u7136\u540e\u5728\u5faa\u73af\u4e2d\u6839\u636e\u8be5\u53d8\u91cf\u7684\u503c\u6765\u51b3\u5b9a\u662f\u5426\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf\u6765\u63a7\u5236\u5faa\u73af\u7684\u9000\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">continue_loop = True<\/p>\n<p>count = 0<\/p>\n<p>while continue_loop:<\/p>\n<p>    print(&quot;This is an infinite loop&quot;)<\/p>\n<p>    count += 1<\/p>\n<p>    if count &gt;= 10:<\/p>\n<p>        continue_loop = False<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u6253\u5370&quot;This is an infinite loop&quot;\u5341\u6b21\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u7efc\u5408\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u7f16\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u7efc\u5408\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u5904\u7406\u65e0\u9650\u5faa\u73af\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u5faa\u73af\u4e2d\u8bbe\u7f6e\u6761\u4ef6\u53d8\u91cf\uff0c\u5e76\u7ed3\u5408try-except\u8bed\u53e5\u6765\u6355\u6349KeyboardInterrupt\u5f02\u5e38\uff0c\u4ece\u800c\u5b9e\u73b0\u66f4\u52a0\u7075\u6d3b\u7684\u5faa\u73af\u63a7\u5236\u3002<\/p>\n<\/p>\n<ol>\n<li>\u7efc\u5408\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf\u548c\u5f02\u5e38\u5904\u7406<\/li>\n<\/ol>\n<p><p>\u4ee5\u4e0b\u4ee3\u7801\u7efc\u5408\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf\u548c\u5f02\u5e38\u5904\u7406\u673a\u5236\u6765\u63a7\u5236\u5faa\u73af\u7684\u9000\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">continue_loop = True<\/p>\n<p>count = 0<\/p>\n<p>try:<\/p>\n<p>    while continue_loop:<\/p>\n<p>        print(&quot;This is an infinite loop&quot;)<\/p>\n<p>        count += 1<\/p>\n<p>        if count &gt;= 10:<\/p>\n<p>            continue_loop = False<\/p>\n<p>except KeyboardInterrupt:<\/p>\n<p>    print(&quot;Loop interrupted by user&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u6253\u5370&quot;This is an infinite loop&quot;\u5341\u6b21\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002\u5982\u679c\u5728\u5faa\u73af\u8fc7\u7a0b\u4e2d\u6309\u4e0bCtrl+C\uff0c\u4ee3\u7801\u4f1a\u6355\u6349\u5230KeyboardInterrupt\u5f02\u5e38\uff0c\u5e76\u6253\u5370&quot;Loop interrupted by user&quot;\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528\u81ea\u5b9a\u4e49\u5f02\u5e38\u548c\u6761\u4ef6\u53d8\u91cf<\/li>\n<\/ol>\n<p><p>\u8fd8\u53ef\u4ee5\u7ed3\u5408\u81ea\u5b9a\u4e49\u5f02\u5e38\u548c\u6761\u4ef6\u53d8\u91cf\u6765\u5b9e\u73b0\u66f4\u52a0\u7075\u6d3b\u7684\u5faa\u73af\u63a7\u5236\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u65f6\u5f15\u53d1\u81ea\u5b9a\u4e49\u5f02\u5e38\uff0c\u5e76\u5728\u6355\u6349\u5230\u5f02\u5e38\u65f6\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class CustomException(Exception):<\/p>\n<p>    pass<\/p>\n<p>continue_loop = True<\/p>\n<p>count = 0<\/p>\n<p>try:<\/p>\n<p>    while continue_loop:<\/p>\n<p>        print(&quot;This is an infinite loop&quot;)<\/p>\n<p>        count += 1<\/p>\n<p>        if count &gt;= 10:<\/p>\n<p>            raise CustomException(&quot;Reached maximum count&quot;)<\/p>\n<p>except CustomException as e:<\/p>\n<p>    print(e)<\/p>\n<p>except KeyboardInterrupt:<\/p>\n<p>    print(&quot;Loop interrupted by user&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u6253\u5370&quot;This is an infinite loop&quot;\u5341\u6b21\uff0c\u7136\u540e\u5f15\u53d1CustomException\u5f02\u5e38\uff0c\u5e76\u6253\u5370&quot;Reached maximum count&quot;\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002\u5982\u679c\u5728\u5faa\u73af\u8fc7\u7a0b\u4e2d\u6309\u4e0bCtrl+C\uff0c\u4ee3\u7801\u4f1a\u6355\u6349\u5230KeyboardInterrupt\u5f02\u5e38\uff0c\u5e76\u6253\u5370&quot;Loop interrupted by user&quot;\uff0c\u7136\u540e\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u603b\u4e4b\uff0c<strong>\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u6765\u5f3a\u5236\u7ed3\u675f\u65e0\u9650\u5faa\u73af\uff0c\u5305\u62ec\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C\u3001\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u673a\u5236\u3001\u8bbe\u7f6e\u6761\u4ef6\u9000\u51fa\u5faa\u73af\u4ee5\u53ca\u7efc\u5408\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u3002<\/strong>\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u5904\u7406\u65e0\u9650\u5faa\u73af\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e2d\uff0c\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5b89\u5168\u5730\u7ec8\u6b62\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff1f<\/strong><br \/>\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u952e\u76d8\u7ec4\u5408Ctrl + C\u6765\u4e2d\u65ad\u6b63\u5728\u8fd0\u884c\u7684\u65e0\u9650\u5faa\u73af\u3002\u8fd9\u4f1a\u5f15\u53d1\u4e00\u4e2aKeyboardInterrupt\u5f02\u5e38\uff0c\u5141\u8bb8\u60a8\u505c\u6b62\u5f53\u524d\u7684\u6267\u884c\u3002\u8fd9\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\u3002<\/p>\n<p><strong>\u5982\u679cCtrl + C\u65e0\u6548\uff0c\u8fd8\u6709\u5176\u4ed6\u7ec8\u6b62\u65e0\u9650\u5faa\u73af\u7684\u65b9\u5f0f\u5417\uff1f<\/strong><br \/>\u5982\u679cCtrl + C\u672a\u80fd\u7ec8\u6b62\u7a0b\u5e8f\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u5173\u95edPython\u4ea4\u4e92\u6a21\u5f0f\u7684\u7a97\u53e3\u3002\u8fd9\u4f1a\u5f3a\u5236\u7ed3\u675f\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u4f46\u9700\u6ce8\u610f\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u672a\u4fdd\u5b58\u7684\u6570\u636e\u4e22\u5931\u3002\u786e\u4fdd\u5728\u5173\u95ed\u4e4b\u524d\u4fdd\u5b58\u91cd\u8981\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u7f16\u5199\u4ee3\u7801\u65f6\u907f\u514d\u8fdb\u5165\u65e0\u9650\u5faa\u73af\uff1f<\/strong><br \/>\u4e3a\u4e86\u907f\u514d\u5728\u4ee3\u7801\u4e2d\u51fa\u73b0\u65e0\u9650\u5faa\u73af\uff0c\u60a8\u53ef\u4ee5\u5728\u5faa\u73af\u6761\u4ef6\u4e2d\u6dfb\u52a0\u9002\u5f53\u7684\u7ec8\u6b62\u6761\u4ef6\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u8ba1\u6570\u5668\u6216\u8bbe\u7f6e\u65f6\u95f4\u9650\u5236\u6765\u786e\u4fdd\u5faa\u73af\u5728\u9884\u5b9a\u6b21\u6570\u540e\u505c\u6b62\u3002\u6b64\u5916\uff0c\u8c03\u8bd5\u4ee3\u7801\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528print\u8bed\u53e5\u6216\u65ad\u70b9\u8c03\u8bd5\u6765\u76d1\u6d4b\u5faa\u73af\u72b6\u6001\uff0c\u53ca\u65f6\u53d1\u73b0\u6f5c\u5728\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u5f3a\u5236\u7ed3\u675f\u65e0\u9650\u5faa\u73af\uff1a\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+C\u3001\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u673a\u5236\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1070692,"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\/1070680"}],"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=1070680"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1070680\/revisions"}],"predecessor-version":[{"id":1070694,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1070680\/revisions\/1070694"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1070692"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1070680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1070680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1070680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}