{"id":1109268,"date":"2025-01-08T17:08:31","date_gmt":"2025-01-08T09:08:31","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1109268.html"},"modified":"2025-01-08T17:08:33","modified_gmt":"2025-01-08T09:08:33","slug":"python%e4%b8%adwhile%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b8%a4%e4%b8%aa%e6%9d%a1%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1109268.html","title":{"rendered":"python\u4e2dwhile\u5982\u4f55\u5b9a\u4e24\u4e2a\u6761\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25072621\/58c531dd-3fe8-40e3-a3ba-8724b2db4364.webp\" alt=\"python\u4e2dwhile\u5982\u4f55\u5b9a\u4e24\u4e2a\u6761\u4ef6\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u4f7f\u7528while\u5faa\u73af\u53ef\u4ee5\u901a\u8fc7\u903b\u8f91\u8fd0\u7b97\u7b26\u6765\u8bbe\u5b9a\u4e24\u4e2a\u6761\u4ef6\uff1a\u4f7f\u7528and\u3001or\u6216not\u7b49\u903b\u8f91\u8fd0\u7b97\u7b26\u53ef\u4ee5\u7ed3\u5408\u591a\u4e2a\u6761\u4ef6\u3002<\/strong>\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>while<\/code>\u5faa\u73af\u6765\u68c0\u67e5\u4e24\u4e2a\u6761\u4ef6\u662f\u5426\u90fd\u4e3a\u771f\uff0c\u6216\u8005\u53ea\u9700\u5176\u4e2d\u4e00\u4e2a\u6761\u4ef6\u4e3a\u771f\u3002\u5e38\u89c1\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\u5305\u62ec\uff1aand\u3001or\u3001not\u3002\u63a5\u4e0b\u6765\u8be6\u7ec6\u8bb2\u89e3\u5176\u4e2d\u7684\u4e00\u79cd\u60c5\u51b5\uff1a\u4f7f\u7528<code>and<\/code>\u903b\u8f91\u8fd0\u7b97\u7b26\u6765\u7ed3\u5408\u4e24\u4e2a\u6761\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>and<\/code>\u903b\u8f91\u8fd0\u7b97\u7b26\u65f6\uff0c\u53ea\u6709\u5f53\u4e24\u4e2a\u6761\u4ef6\u90fd\u4e3a\u771f\u65f6\uff0c\u5faa\u73af\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u3002\u8fd9\u5728\u9700\u8981\u786e\u4fdd\u4e24\u4e2a\u6761\u4ef6\u540c\u65f6\u6ee1\u8db3\u65f6\u975e\u5e38\u6709\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528<code>and<\/code>\u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 0<\/p>\n<p>y = 10<\/p>\n<p>while x &lt; 5 and y &gt; 5:<\/p>\n<p>    print(f&quot;x: {x}, y: {y}&quot;)<\/p>\n<p>    x += 1<\/p>\n<p>    y -= 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230x\u4e0d\u518d\u5c0f\u4e8e5\u6216y\u4e0d\u518d\u5927\u4e8e5\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0cx\u7684\u503c\u589e\u52a01\uff0c\u800cy\u7684\u503c\u51cf\u5c0f1\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u903b\u8f91\u8fd0\u7b97\u7b26\u7ed3\u5408\u4e24\u4e2a\u6761\u4ef6<\/h2>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528 <code>and<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528 <code>and<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26\u53ef\u4ee5\u786e\u4fdd\u4e24\u4e2a\u6761\u4ef6\u90fd\u4e3a\u771f\u65f6\uff0c\u5faa\u73af\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8be6\u7ec6\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 0<\/p>\n<p>y = 10<\/p>\n<p>while x &lt; 5 and y &gt; 5:<\/p>\n<p>    print(f&quot;x: {x}, y: {y}&quot;)<\/p>\n<p>    x += 1<\/p>\n<p>    y -= 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u521d\u59cb\u503cx\u4e3a0\uff0cy\u4e3a10\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230x\u4e0d\u518d\u5c0f\u4e8e5\u6216y\u4e0d\u518d\u5927\u4e8e5\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0cx\u7684\u503c\u589e\u52a01\uff0c\u800cy\u7684\u503c\u51cf\u5c0f1\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528 <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528 <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26\u53ef\u4ee5\u786e\u4fdd\u53ea\u8981\u6709\u4e00\u4e2a\u6761\u4ef6\u4e3a\u771f\uff0c\u5faa\u73af\u5c31\u4f1a\u7ee7\u7eed\u6267\u884c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8be6\u7ec6\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 0<\/p>\n<p>y = 10<\/p>\n<p>while x &lt; 5 or y &gt; 5:<\/p>\n<p>    print(f&quot;x: {x}, y: {y}&quot;)<\/p>\n<p>    x += 1<\/p>\n<p>    y -= 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230x\u4e0d\u518d\u5c0f\u4e8e5\u5e76\u4e14y\u4e0d\u518d\u5927\u4e8e5\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0cx\u7684\u503c\u589e\u52a01\uff0c\u800cy\u7684\u503c\u51cf\u5c0f1\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u7ed3\u5408\u903b\u8f91\u8fd0\u7b97\u7b26\u548c\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h2>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528 <code>and<\/code> \u7ed3\u5408\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5e38\u5e38\u9700\u8981\u7ed3\u5408\u903b\u8f91\u8fd0\u7b97\u7b26\u548c\u6bd4\u8f83\u8fd0\u7b97\u7b26\u6765\u5b9e\u73b0\u590d\u6742\u7684\u6761\u4ef6\u5224\u65ad\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">temperature = 20<\/p>\n<p>humidity = 70<\/p>\n<p>while temperature &lt; 25 and humidity &gt; 60:<\/p>\n<p>    print(f&quot;Temperature: {temperature}, Humidity: {humidity}&quot;)<\/p>\n<p>    temperature += 1<\/p>\n<p>    humidity -= 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u521d\u59cb\u503ctemperature\u4e3a20\uff0chumidity\u4e3a70\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230temperature\u4e0d\u518d\u5c0f\u4e8e25\u6216humidity\u4e0d\u518d\u5927\u4e8e60\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0ctemperature\u7684\u503c\u589e\u52a01\uff0c\u800chumidity\u7684\u503c\u51cf\u5c0f2\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528 <code>or<\/code> \u7ed3\u5408\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 <code>or<\/code> \u7ed3\u5408\u6bd4\u8f83\u8fd0\u7b97\u7b26\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">temperature = 20<\/p>\n<p>humidity = 70<\/p>\n<p>while temperature &lt; 25 or humidity &gt; 60:<\/p>\n<p>    print(f&quot;Temperature: {temperature}, Humidity: {humidity}&quot;)<\/p>\n<p>    temperature += 1<\/p>\n<p>    humidity -= 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230temperature\u4e0d\u518d\u5c0f\u4e8e25\u5e76\u4e14humidity\u4e0d\u518d\u5927\u4e8e60\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0ctemperature\u7684\u503c\u589e\u52a01\uff0c\u800chumidity\u7684\u503c\u51cf\u5c0f2\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u7ed3\u5408\u903b\u8f91\u8fd0\u7b97\u7b26\u548c\u5e03\u5c14\u53d8\u91cf<\/h2>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528\u5e03\u5c14\u53d8\u91cf\u548c <code>and<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u5e03\u5c14\u53d8\u91cf\u6765\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">keep_running = True<\/p>\n<p>count = 0<\/p>\n<p>while keep_running and count &lt; 10:<\/p>\n<p>    print(f&quot;Count: {count}&quot;)<\/p>\n<p>    count += 1<\/p>\n<p>    if count == 5:<\/p>\n<p>        keep_running = False<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230count\u8fbe\u523010\u6216keep_running\u53d8\u4e3aFalse\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0ccount\u7684\u503c\u589e\u52a01\uff0c\u5f53count\u8fbe\u52305\u65f6\uff0ckeep_running\u88ab\u8bbe\u7f6e\u4e3aFalse\uff0c\u4ece\u800c\u7ec8\u6b62\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528\u5e03\u5c14\u53d8\u91cf\u548c <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u5e03\u5c14\u53d8\u91cf\u548c <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">keep_running = True<\/p>\n<p>count = 0<\/p>\n<p>while keep_running or count &lt; 10:<\/p>\n<p>    print(f&quot;Count: {count}&quot;)<\/p>\n<p>    count += 1<\/p>\n<p>    if count == 5:<\/p>\n<p>        keep_running = False<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230count\u8fbe\u523010\u5e76\u4e14keep_running\u53d8\u4e3aFalse\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0ccount\u7684\u503c\u589e\u52a01\uff0c\u5f53count\u8fbe\u52305\u65f6\uff0ckeep_running\u88ab\u8bbe\u7f6e\u4e3aFalse\uff0c\u4f46\u7531\u4e8e <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u5b58\u5728\uff0c\u5faa\u73af\u4f1a\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230count\u8fbe\u523010\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u7ed3\u5408\u903b\u8f91\u8fd0\u7b97\u7b26\u548c\u51fd\u6570<\/h2>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528\u51fd\u6570\u548c <code>and<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u53ef\u4ee5\u7528\u4e8e\u5c01\u88c5\u590d\u6742\u7684\u6761\u4ef6\u5224\u65ad\u903b\u8f91\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def is_temperature_<a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>(temp):<\/p>\n<p>    return temp &lt; 25<\/p>\n<p>def is_humidity_safe(hum):<\/p>\n<p>    return hum &gt; 60<\/p>\n<p>temperature = 20<\/p>\n<p>humidity = 70<\/p>\n<p>while is_temperature_safe(temperature) and is_humidity_safe(humidity):<\/p>\n<p>    print(f&quot;Temperature: {temperature}, Humidity: {humidity}&quot;)<\/p>\n<p>    temperature += 1<\/p>\n<p>    humidity -= 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u4e24\u4e2a\u51fd\u6570 <code>is_temperature_safe<\/code> \u548c <code>is_humidity_safe<\/code> \u7528\u4e8e\u5224\u65ad\u6e29\u5ea6\u548c\u6e7f\u5ea6\u662f\u5426\u5728\u5b89\u5168\u8303\u56f4\u5185\u3002\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230temperature\u4e0d\u518d\u5c0f\u4e8e25\u6216humidity\u4e0d\u518d\u5927\u4e8e60\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528\u51fd\u6570\u548c <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u51fd\u6570\u548c <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def is_temperature_safe(temp):<\/p>\n<p>    return temp &lt; 25<\/p>\n<p>def is_humidity_safe(hum):<\/p>\n<p>    return hum &gt; 60<\/p>\n<p>temperature = 20<\/p>\n<p>humidity = 70<\/p>\n<p>while is_temperature_safe(temperature) or is_humidity_safe(humidity):<\/p>\n<p>    print(f&quot;Temperature: {temperature}, Humidity: {humidity}&quot;)<\/p>\n<p>    temperature += 1<\/p>\n<p>    humidity -= 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230temperature\u4e0d\u518d\u5c0f\u4e8e25\u5e76\u4e14humidity\u4e0d\u518d\u5927\u4e8e60\u3002\u6bcf\u6b21\u5faa\u73af\u4e2d\uff0ctemperature\u7684\u503c\u589e\u52a01\uff0c\u800chumidity\u7684\u503c\u51cf\u5c0f2\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u7ed3\u5408\u903b\u8f91\u8fd0\u7b97\u7b26\u548c\u7528\u6237\u8f93\u5165<\/h2>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528\u7528\u6237\u8f93\u5165\u548c <code>and<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u6839\u636e\u7528\u6237\u8f93\u5165\u6765\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = int(input(&quot;Enter a value for x: &quot;))<\/p>\n<p>y = int(input(&quot;Enter a value for y: &quot;))<\/p>\n<p>while x &lt; 5 and y &gt; 5:<\/p>\n<p>    print(f&quot;x: {x}, y: {y}&quot;)<\/p>\n<p>    x += 1<\/p>\n<p>    y -= 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7528\u6237\u8f93\u5165\u7528\u4e8e\u521d\u59cb\u5316x\u548cy\u7684\u503c\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230x\u4e0d\u518d\u5c0f\u4e8e5\u6216y\u4e0d\u518d\u5927\u4e8e5\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528\u7528\u6237\u8f93\u5165\u548c <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u7528\u6237\u8f93\u5165\u548c <code>or<\/code> \u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = int(input(&quot;Enter a value for x: &quot;))<\/p>\n<p>y = int(input(&quot;Enter a value for y: &quot;))<\/p>\n<p>while x &lt; 5 or y &gt; 5:<\/p>\n<p>    print(f&quot;x: {x}, y: {y}&quot;)<\/p>\n<p>    x += 1<\/p>\n<p>    y -= 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5faa\u73af\u5c06\u7ee7\u7eed\u6267\u884c\uff0c\u76f4\u5230x\u4e0d\u518d\u5c0f\u4e8e5\u5e76\u4e14y\u4e0d\u518d\u5927\u4e8e5\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u793a\u4f8b\uff0c\u53ef\u4ee5\u770b\u51fa\u4f7f\u7528\u903b\u8f91\u8fd0\u7b97\u7b26\u7ed3\u5408\u591a\u4e2a\u6761\u4ef6\u7684\u7075\u6d3b\u6027\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\u548c\u6761\u4ef6\u7ec4\u5408\uff0c\u5b9e\u73b0\u590d\u6742\u7684\u5faa\u73af\u63a7\u5236\u903b\u8f91\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u5728while\u5faa\u73af\u4e2d\u540c\u65f6\u4f7f\u7528\u591a\u4e2a\u6761\u4ef6\uff1f<\/strong><br \/>\u5728Python\u7684while\u5faa\u73af\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u903b\u8f91\u8fd0\u7b97\u7b26\uff08\u5982<code>and<\/code>\u548c<code>or<\/code>\uff09\u6765\u7ed3\u5408\u591a\u4e2a\u6761\u4ef6\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u8981\u5728\u4e24\u4e2a\u6761\u4ef6\u90fd\u4e3a\u771f\u65f6\u6267\u884c\u5faa\u73af\uff0c\u53ef\u4ee5\u4f7f\u7528<code>while condition1 and condition2:<\/code>\u3002\u8fd9\u6837\uff0c\u53ea\u6709\u5728\u4e24\u4e2a\u6761\u4ef6\u90fd\u6ee1\u8db3\u65f6\uff0c\u5faa\u73af\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p><strong>\u4f7f\u7528\u591a\u4e2a\u6761\u4ef6\u65f6\uff0c\u5982\u4f55\u786e\u4fdd\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff1f<\/strong><br \/>\u4e3a\u4e86\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u5c06\u590d\u6742\u7684\u6761\u4ef6\u62c6\u5206\u6210\u591a\u4e2a\u53d8\u91cf\uff0c\u5e76\u5728while\u5faa\u73af\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u53d8\u91cf\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5b9a\u4e49<code>is_condition1_met<\/code>\u548c<code>is_condition2_met<\/code>\u4e24\u4e2a\u5e03\u5c14\u53d8\u91cf\uff0c\u7136\u540e\u5728while\u5faa\u73af\u4e2d\u4f7f\u7528\u5b83\u4eec\u3002\u8fd9\u79cd\u65b9\u6cd5\u4f7f\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\uff0c\u4fbf\u4e8e\u540e\u7eed\u7ef4\u62a4\u548c\u8c03\u8bd5\u3002<\/p>\n<p><strong>\u5728while\u5faa\u73af\u4e2d\u4f7f\u7528\u591a\u4e2a\u6761\u4ef6\u65f6\uff0c\u5982\u4f55\u907f\u514d\u65e0\u9650\u5faa\u73af\uff1f<\/strong><br \/>\u786e\u4fdd\u5728\u5faa\u73af\u5185\u90e8\u6709\u9002\u5f53\u7684\u6761\u4ef6\u66f4\u65b0\uff0c\u4ee5\u907f\u514d\u65e0\u9650\u5faa\u73af\u3002\u5982\u679c\u5728while\u5faa\u73af\u7684\u6761\u4ef6\u4e2d\u4f7f\u7528\u53d8\u91cf\uff0c\u52a1\u5fc5\u5728\u5faa\u73af\u4f53\u5185\u4fee\u6539\u8fd9\u4e9b\u53d8\u91cf\u7684\u503c\uff0c\u4ee5\u4f7f\u6761\u4ef6\u5728\u67d0\u4e2a\u65f6\u523b\u53d8\u4e3aFalse\uff0c\u4ece\u800c\u4f7f\u5faa\u73af\u7ed3\u675f\u3002\u53ef\u4ee5\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u5728\u7279\u5b9a\u6761\u4ef6\u4e0b\u5f3a\u5236\u9000\u51fa\u5faa\u73af\uff0c\u4ee5\u9632\u6b62\u7a0b\u5e8f\u5361\u4f4f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u4f7f\u7528while\u5faa\u73af\u53ef\u4ee5\u901a\u8fc7\u903b\u8f91\u8fd0\u7b97\u7b26\u6765\u8bbe\u5b9a\u4e24\u4e2a\u6761\u4ef6\uff1a\u4f7f\u7528and\u3001or\u6216not\u7b49\u903b\u8f91\u8fd0\u7b97\u7b26\u53ef\u4ee5\u7ed3 [&hellip;]","protected":false},"author":3,"featured_media":1109278,"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\/1109268"}],"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=1109268"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1109268\/revisions"}],"predecessor-version":[{"id":1109281,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1109268\/revisions\/1109281"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1109278"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1109268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1109268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1109268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}