{"id":994830,"date":"2024-12-27T08:58:57","date_gmt":"2024-12-27T00:58:57","guid":{"rendered":""},"modified":"2024-12-27T08:58:59","modified_gmt":"2024-12-27T00:58:59","slug":"python%e5%a6%82%e4%bd%95%e6%97%a0%e9%99%90%e5%be%aa%e7%8e%af%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/994830.html","title":{"rendered":"python\u5982\u4f55\u65e0\u9650\u5faa\u73af\u8bed\u53e5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25071632\/0263c403-cfde-47d8-ab16-1c79a4a4b653.webp\" alt=\"python\u5982\u4f55\u65e0\u9650\u5faa\u73af\u8bed\u53e5\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u8981\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\uff0c\u53ef\u4ee5\u4f7f\u7528<code>while True<\/code>\u8bed\u53e5\u3001\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u6216\u57fa\u4e8e\u751f\u6210\u5668\u7684\u65b9\u5f0f\u3002<\/strong>\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd<code>while True<\/code>\u8bed\u53e5\u8fd9\u4e00\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u662f\u6700\u5e38\u89c1\u4e14\u6613\u4e8e\u7406\u89e3\u7684\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>while True<\/code>\u8bed\u53e5\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u5728Python\u4e2d\uff0c<code>while<\/code>\u5faa\u73af\u4f1a\u91cd\u590d\u6267\u884c\u4ee3\u7801\u5757\uff0c\u76f4\u5230\u6761\u4ef6\u4e0d\u518d\u4e3a\u771f\u3002\u5f53\u6761\u4ef6\u88ab\u8bbe\u5b9a\u4e3a<code>True<\/code>\u65f6\uff0c\u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\u3002\u901a\u5e38\uff0c\u8fd9\u79cd\u5faa\u73af\u4f1a\u914d\u5408<code>break<\/code>\u8bed\u53e5\u6765\u7ec8\u6b62\u5faa\u73af\uff0c\u4ee5\u907f\u514d\u7a0b\u5e8f\u8fdb\u5165\u6b7b\u5faa\u73af\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    # \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c<\/p>\n<p>    user_input = input(&quot;\u8f93\u5165&#39;\u9000\u51fa&#39;\u4ee5\u7ed3\u675f\u5faa\u73af\uff1a&quot;)<\/p>\n<p>    if user_input == &#39;\u9000\u51fa&#39;:<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u7a0b\u5e8f\u4f1a\u6301\u7eed\u8981\u6c42\u7528\u6237\u8f93\u5165\uff0c\u76f4\u5230\u7528\u6237\u8f93\u5165\u201c\u9000\u51fa\u201d\uff0c\u5faa\u73af\u624d\u4f1a\u7ec8\u6b62\u3002\u8fd9\u79cd\u6a21\u5f0f\u975e\u5e38\u9002\u5408\u9700\u8981\u6301\u7eed\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u6bd4\u5982\u670d\u52a1\u5668\u76d1\u542c\u8bf7\u6c42\u6216\u7528\u6237\u4ea4\u4e92\u5f0f\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001WHILE TRUE\u7684\u4f7f\u7528<\/h3>\n<\/p>\n<p><p><strong>1\u3001\u57fa\u672c\u7528\u6cd5<\/strong><\/p>\n<\/p>\n<p><p><code>while True<\/code>\u662fPython\u4e2d\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u7684\u4e00\u79cd\u5e38\u89c1\u65b9\u5f0f\u3002\u7531\u4e8e\u6761\u4ef6\u59cb\u7ec8\u4e3a\u771f\uff0c\u4ee3\u7801\u5757\u4f1a\u88ab\u6301\u7eed\u6267\u884c\u3002\u901a\u5e38\uff0c\u8fd9\u79cd\u5faa\u73af\u4f1a\u5728\u67d0\u79cd\u6761\u4ef6\u6ee1\u8db3\u65f6\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u8df3\u51fa\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c<code>while True<\/code>\u53ef\u4ee5\u7528\u4e8e\u9700\u8981\u6301\u7eed\u8fd0\u884c\u7684\u4efb\u52a1\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u7f51\u7edc\u670d\u52a1\u5668\u53ef\u80fd\u4f1a\u4f7f\u7528<code>while True<\/code>\u6765\u6301\u7eed\u76d1\u542c\u5ba2\u6237\u7aef\u8fde\u63a5\u8bf7\u6c42\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528<code>while True<\/code>\u6765\u5b9e\u73b0\u7528\u6237\u8f93\u5165\u7684\u6301\u7eed\u8bfb\u53d6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    command = input(&quot;\u8bf7\u8f93\u5165\u547d\u4ee4\uff1a&quot;)<\/p>\n<p>    if command == &quot;exit&quot;:<\/p>\n<p>        print(&quot;\u5faa\u73af\u7ed3\u675f&quot;)<\/p>\n<p>        break<\/p>\n<p>    else:<\/p>\n<p>        print(f&quot;\u60a8\u8f93\u5165\u7684\u547d\u4ee4\u662f: {command}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u7a0b\u5e8f\u4f1a\u6301\u7eed\u8981\u6c42\u7528\u6237\u8f93\u5165\u547d\u4ee4\uff0c\u5e76\u5728\u7528\u6237\u8f93\u5165\u201cexit\u201d\u65f6\u7ec8\u6b62\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p><strong>2\u3001\u914d\u5408\u6761\u4ef6\u5224\u65ad<\/strong><\/p>\n<\/p>\n<p><p>\u5728<code>while True<\/code>\u5faa\u73af\u4e2d\uff0c\u901a\u5e38\u4f1a\u642d\u914d\u6761\u4ef6\u5224\u65ad\uff0c\u4ee5\u4fbf\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u9000\u51fa\u5faa\u73af\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u786e\u4fdd\u5faa\u73af\u5728\u9700\u8981\u65f6\u80fd\u591f\u6b63\u5e38\u7ed3\u675f\uff0c\u907f\u514d\u6b7b\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u7a0b\u5e8f\u9700\u8981\u5904\u7406\u7528\u6237\u7684\u8f93\u5165\uff0c\u4f46\u53ea\u6709\u5728\u7528\u6237\u8f93\u5165\u7279\u5b9a\u6307\u4ee4\u65f6\u624d\u4f1a\u7ee7\u7eed\u5904\u7406\uff0c\u5426\u5219\u63d0\u793a\u9519\u8bef\u4fe1\u606f\u5e76\u8981\u6c42\u91cd\u65b0\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    command = input(&quot;\u8bf7\u8f93\u5165\u6709\u6548\u7684\u547d\u4ee4\uff1a&quot;)<\/p>\n<p>    if command in [&quot;start&quot;, &quot;stop&quot;, &quot;pause&quot;]:<\/p>\n<p>        print(f&quot;\u6267\u884c\u547d\u4ee4: {command}&quot;)<\/p>\n<p>        # \u6267\u884c\u76f8\u5173\u64cd\u4f5c<\/p>\n<p>    elif command == &quot;exit&quot;:<\/p>\n<p>        print(&quot;\u9000\u51fa\u7a0b\u5e8f&quot;)<\/p>\n<p>        break<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;\u65e0\u6548\u547d\u4ee4\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\u3002&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u5728\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u65f6\u6b63\u5e38\u9000\u51fa\uff0c\u540c\u65f6\u5728\u65e0\u6548\u8f93\u5165\u65f6\u63d0\u4f9b\u53cd\u9988\u5e76\u7ee7\u7eed\u7b49\u5f85\u7528\u6237\u8f93\u5165\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u9012\u5f52\u5b9e\u73b0\u65e0\u9650\u5faa\u73af<\/h3>\n<\/p>\n<p><p><strong>1\u3001\u9012\u5f52\u51fd\u6570<\/strong><\/p>\n<\/p>\n<p><p>\u9012\u5f52\u662f\u6307\u5728\u51fd\u6570\u5185\u90e8\u8c03\u7528\u81ea\u8eab\u3002\u901a\u8fc7\u9012\u5f52\u8c03\u7528\uff0c\u53ef\u4ee5\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u3002\u7136\u800c\uff0c\u4f7f\u7528\u9012\u5f52\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u9700\u8c28\u614e\uff0c\u56e0\u4e3aPython\u6709\u9012\u5f52\u6df1\u5ea6\u9650\u5236\uff0c\u8fc7\u6df1\u7684\u9012\u5f52\u4f1a\u5bfc\u81f4\u6808\u6ea2\u51fa\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u9012\u5f52\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u901a\u8fc7\u9012\u5f52\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def recursive_loop():<\/p>\n<p>    command = input(&quot;\u8bf7\u8f93\u5165\u547d\u4ee4\uff1a&quot;)<\/p>\n<p>    if command == &quot;exit&quot;:<\/p>\n<p>        print(&quot;\u5faa\u73af\u7ed3\u675f&quot;)<\/p>\n<p>        return<\/p>\n<p>    else:<\/p>\n<p>        print(f&quot;\u60a8\u8f93\u5165\u7684\u547d\u4ee4\u662f: {command}&quot;)<\/p>\n<p>        recursive_loop()<\/p>\n<p>recursive_loop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u51fd\u6570<code>recursive_loop<\/code>\u4f1a\u5728\u6bcf\u6b21\u8c03\u7528\u65f6\u8981\u6c42\u7528\u6237\u8f93\u5165\uff0c\u5e76\u5728\u7528\u6237\u8f93\u5165\u201cexit\u201d\u65f6\u7ed3\u675f\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p><strong>2\u3001\u9012\u5f52\u7684\u4f18\u7f3a\u70b9<\/strong><\/p>\n<\/p>\n<p><p>\u9012\u5f52\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u7b80\u6d01\u660e\u4e86\uff0c\u4f46\u7f3a\u70b9\u4e5f\u5f88\u660e\u663e\uff0c\u5373\u53ef\u80fd\u5bfc\u81f4\u6808\u6ea2\u51fa\u3002\u6b64\u5916\uff0c\u9012\u5f52\u901a\u5e38\u4e0d\u5982\u5faa\u73af\u8bed\u53e5\u5728\u6027\u80fd\u4e0a\u9ad8\u6548\uff0c\u56e0\u6b64\u5728\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u65f6\uff0c\u901a\u5e38\u66f4\u63a8\u8350\u4f7f\u7528<code>while True<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u751f\u6210\u5668\u5b9e\u73b0\u65e0\u9650\u5faa\u73af<\/h3>\n<\/p>\n<p><p><strong>1\u3001\u751f\u6210\u5668\u7684\u57fa\u7840<\/strong><\/p>\n<\/p>\n<p><p>\u751f\u6210\u5668\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u8fed\u4ee3\u5668\uff0c\u4f7f\u7528<code>yield<\/code>\u5173\u952e\u5b57\u8fd4\u56de\u503c\u3002\u751f\u6210\u5668\u51fd\u6570\u5728\u6bcf\u6b21\u8c03\u7528\u65f6\u90fd\u4f1a\u6682\u505c\uff0c\u5e76\u5728\u4e0b\u6b21\u8c03\u7528\u65f6\u4ece\u6682\u505c\u7684\u4f4d\u7f6e\u7ee7\u7eed\u6267\u884c\u3002\u901a\u8fc7\u4f7f\u7528\u751f\u6210\u5668\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u770b\u4f3c\u65e0\u9650\u7684\u5e8f\u5217\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u751f\u6210\u5668\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def infinite_sequence():<\/p>\n<p>    num = 0<\/p>\n<p>    while True:<\/p>\n<p>        yield num<\/p>\n<p>        num += 1<\/p>\n<p>for i in infinite_sequence():<\/p>\n<p>    print(i)<\/p>\n<p>    if i &gt;= 10:  # \u4ec5\u4e3a\u6f14\u793a\u76ee\u7684\uff0c\u907f\u514d\u65e0\u9650\u8f93\u51fa<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u751f\u6210\u5668<code>infinite_sequence<\/code>\u4f1a\u4e0d\u65ad\u751f\u6210\u4ece0\u5f00\u59cb\u7684\u6574\u6570\u3002<\/p>\n<\/p>\n<p><p><strong>2\u3001\u751f\u6210\u5668\u7684\u5e94\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u751f\u6210\u5668\u7279\u522b\u9002\u5408\u7528\u4e8e\u751f\u6210\u770b\u4f3c\u65e0\u9650\u7684\u6570\u636e\u6d41\uff0c\u4f8b\u5982\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u9010\u6b65\u751f\u6210\u7ed3\u679c\uff0c\u907f\u514d\u4e00\u6b21\u6027\u5c06\u6240\u6709\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u901a\u8fc7\u751f\u6210\u5668\uff0c\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u5185\u5b58\u4f7f\u7528\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5047\u8bbe\u6211\u4eec\u9700\u8981\u5904\u7406\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u751f\u6210\u5668\u9010\u884c\u8bfb\u53d6\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u5c06\u6574\u4e2a\u6587\u4ef6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def read_large_file(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;) as file:<\/p>\n<p>        for line in file:<\/p>\n<p>            yield line.strip()<\/p>\n<p>for line in read_large_file(&quot;large_file.txt&quot;):<\/p>\n<p>    print(line)<\/p>\n<p>    # \u5728\u8fd9\u91cc\u53ef\u4ee5\u5bf9\u6bcf\u884c\u8fdb\u884c\u5904\u7406<\/p>\n<p>    # \u4e3a\u6f14\u793a\u76ee\u7684\uff0c\u5047\u8bbe\u4ec5\u5904\u7406\u524d10\u884c<\/p>\n<p>    if some_condition:<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u751f\u6210\u5668\uff0c\u6211\u4eec\u80fd\u591f\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\u4fdd\u6301\u8f83\u4f4e\u7684\u5185\u5b58\u5360\u7528\uff0c\u540c\u65f6\u4ecd\u7136\u80fd\u591f\u4ece\u6570\u636e\u6d41\u4e2d\u63d0\u53d6\u6240\u9700\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p><strong>1\u3001\u907f\u514d\u6b7b\u5faa\u73af<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u65f6\uff0c\u52a1\u5fc5\u786e\u4fdd\u5faa\u73af\u80fd\u591f\u5728\u9700\u8981\u65f6\u6b63\u786e\u7ec8\u6b62\u3002\u5426\u5219\uff0c\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u65e0\u6cd5\u6b63\u5e38\u9000\u51fa\uff0c\u6216\u8005\u7cfb\u7edf\u8d44\u6e90\u88ab\u8017\u5c3d\u3002\u901a\u5e38\uff0c\u901a\u8fc7\u6761\u4ef6\u5224\u65ad\u548c<code>break<\/code>\u8bed\u53e5\uff0c\u53ef\u4ee5\u6709\u6548\u907f\u514d\u6b7b\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p><strong>2\u3001\u6027\u80fd\u548c\u6548\u7387<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u7684\u65b9\u5f0f\u65f6\uff0c\u9700\u8003\u8651\u6027\u80fd\u548c\u6548\u7387\u3002<code>while True<\/code>\u901a\u5e38\u662f\u6700\u76f4\u63a5\u548c\u9ad8\u6548\u7684\u65b9\u5f0f\uff0c\u800c\u751f\u6210\u5668\u5219\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u5185\u5b58\u7ba1\u7406\u80fd\u529b\u3002\u9012\u5f52\u5728\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u65f6\u4e0d\u592a\u5e38\u7528\uff0c\u9700\u8c28\u614e\u4f7f\u7528\u4ee5\u907f\u514d\u6808\u6ea2\u51fa\u3002<\/p>\n<\/p>\n<p><p><strong>3\u3001\u4ee3\u7801\u53ef\u8bfb\u6027<\/strong><\/p>\n<\/p>\n<p><p>\u9009\u62e9\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\u7684\u65b9\u5f0f\u65f6\uff0c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u540c\u6837\u91cd\u8981\u3002\u5e94\u9009\u62e9\u6613\u4e8e\u7406\u89e3\u548c\u7ef4\u62a4\u7684\u5b9e\u73b0\u65b9\u5f0f\uff0c\u4ee5\u4fbf\u4e8e\u540e\u7eed\u7684<a href=\"https:\/\/docs.pingcode.com\/code-review\" target=\"_blank\">\u4ee3\u7801\u5ba1\u67e5<\/a>\u548c\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u5408\u7406\u4f7f\u7528<code>while True<\/code>\u3001\u9012\u5f52\u548c\u751f\u6210\u5668\uff0c\u53ef\u4ee5\u5728Python\u4e2d\u5b9e\u73b0\u9ad8\u6548\u548c\u7075\u6d3b\u7684\u65e0\u9650\u5faa\u73af\uff0c\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u573a\u666f\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff0c\u53ef\u4ee5\u4f7f\u7528<code>while<\/code>\u8bed\u53e5\u3002\u53ea\u9700\u5c06\u6761\u4ef6\u8bbe\u7f6e\u4e3a<code>True<\/code>\uff0c\u5982<code>while True:<\/code>\uff0c\u63a5\u4e0b\u6765\u5728\u5faa\u73af\u4f53\u5185\u7f16\u5199\u9700\u8981\u91cd\u590d\u6267\u884c\u7684\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u4e14\u6613\u4e8e\u7406\u89e3\uff0c\u4f46\u4e00\u5b9a\u8981\u786e\u4fdd\u5728\u9002\u5f53\u7684\u65f6\u673a\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\uff0c\u4ee5\u907f\u514d\u7a0b\u5e8f\u65e0\u4f11\u6b62\u5730\u8fd0\u884c\u3002<\/p>\n<p><strong>\u65e0\u9650\u5faa\u73af\u4f1a\u5bf9\u7cfb\u7edf\u6027\u80fd\u4ea7\u751f\u5f71\u54cd\u5417\uff1f<\/strong><br \/>\u65e0\u9650\u5faa\u73af\u5982\u679c\u6ca1\u6709\u9002\u5f53\u7684\u9000\u51fa\u6761\u4ef6\uff0c\u786e\u5b9e\u53ef\u80fd\u4f1a\u5360\u7528\u5927\u91cf\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u5bfc\u81f4CPU\u4f7f\u7528\u7387\u5347\u9ad8\uff0c\u7cfb\u7edf\u53d8\u5f97\u7f13\u6162\u3002\u786e\u4fdd\u5728\u8bbe\u8ba1\u7a0b\u5e8f\u65f6\u8003\u8651\u5230<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/58557.html\" target=\"_blank\">\u8d44\u6e90\u7ba1\u7406<\/a>\uff0c\u5e76\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\u6216\u5f02\u5e38\u5904\u7406\u6765\u5b89\u5168\u5730\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<p><strong>\u5982\u4f55\u5b89\u5168\u5730\u9000\u51fa\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\uff1f<\/strong><br \/>\u5728\u65e0\u9650\u5faa\u73af\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6761\u4ef6\u6765\u5b89\u5168\u9000\u51fa\uff0c\u4f8b\u5982\u4f7f\u7528\u4e00\u4e2a<code>break<\/code>\u8bed\u53e5\u3002\u5f53\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u65f6\uff0c\u53ef\u4ee5\u8c03\u7528<code>break<\/code>\u6765\u7ec8\u6b62\u5faa\u73af\u3002\u6b64\u5916\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u6355\u83b7\u7528\u6237\u8f93\u5165\uff08\u4f8b\u5982\u6309\u4e0b\u7279\u5b9a\u952e\uff09\u6216\u5904\u7406\u7279\u5b9a\u5f02\u5e38\u6765\u5b9e\u73b0\u5b89\u5168\u9000\u51fa\u3002\u8fd9\u79cd\u65b9\u5f0f\u80fd\u6709\u6548\u9632\u6b62\u7a0b\u5e8f\u5d29\u6e83\u6216\u65e0\u54cd\u5e94\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u8981\u5b9e\u73b0\u65e0\u9650\u5faa\u73af\uff0c\u53ef\u4ee5\u4f7f\u7528while True\u8bed\u53e5\u3001\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u6216\u57fa\u4e8e\u751f\u6210\u5668\u7684\u65b9\u5f0f\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6 [&hellip;]","protected":false},"author":3,"featured_media":994838,"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\/994830"}],"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=994830"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/994830\/revisions"}],"predecessor-version":[{"id":994839,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/994830\/revisions\/994839"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/994838"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=994830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=994830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=994830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}