{"id":981045,"date":"2024-12-27T06:59:17","date_gmt":"2024-12-26T22:59:17","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/981045.html"},"modified":"2024-12-27T06:59:19","modified_gmt":"2024-12-26T22:59:19","slug":"python%e5%a6%82%e4%bd%95%e5%be%aa%e7%8e%af%e7%89%b9%e5%ae%9a%e6%ac%a1%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/981045.html","title":{"rendered":"python\u5982\u4f55\u5faa\u73af\u7279\u5b9a\u6b21\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210145\/ea497c8f-871a-4ed5-a2fd-6207e857ba56.webp\" alt=\"python\u5982\u4f55\u5faa\u73af\u7279\u5b9a\u6b21\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5faa\u73af\u7279\u5b9a\u6b21\u6570\u53ef\u4ee5\u4f7f\u7528for\u5faa\u73af\u3001range\u51fd\u6570\u3001while\u5faa\u73af\u7b49\u65b9\u5f0f\u3002for\u5faa\u73af\u901a\u5e38\u7ed3\u5408range\u51fd\u6570\u4f7f\u7528\uff0crange\u51fd\u6570\u53ef\u4ee5\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u6570\u5b57\u5e8f\u5217\uff0cwhile\u5faa\u73af\u5219\u9700\u8981\u624b\u52a8\u63a7\u5236\u5faa\u73af\u6b21\u6570\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528for\u5faa\u73af\u4e0erange\u51fd\u6570<\/strong>\uff1aPython\u4e2d\u7684for\u5faa\u73af\u901a\u5e38\u7ed3\u5408range\u51fd\u6570\u4f7f\u7528\uff0c\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u7b80\u6d01\u4e14\u6613\u4e8e\u7406\u89e3\u3002\u901a\u8fc7range\u51fd\u6570\uff0c\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u6307\u5b9a\u8303\u56f4\u5185\u7684\u6570\u5b57\u5e8f\u5217\uff0c\u7136\u540e\u5728for\u5faa\u73af\u4e2d\u9010\u4e00\u904d\u5386\u8fd9\u4e9b\u6570\u5b57\u3002\u6bd4\u5982\uff0c\u8981\u5faa\u73af5\u6b21\uff0c\u53ef\u4ee5\u5199\u4f5c<code>for i in range(5):<\/code>\uff0c\u8fd9\u6837\u5faa\u73af\u4f53\u5185\u7684\u4ee3\u7801\u5c06\u88ab\u6267\u884c5\u6b21\u3002range\u51fd\u6570\u7684\u53c2\u6570\u53ef\u4ee5\u6307\u5b9a\u8d77\u59cb\u503c\u3001\u7ec8\u6b62\u503c\u548c\u6b65\u957f\uff0c\u9ed8\u8ba4\u8d77\u59cb\u503c\u4e3a0\uff0c\u6b65\u957f\u4e3a1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528while\u5faa\u73af<\/strong>\uff1awhile\u5faa\u73af\u901a\u8fc7\u4e00\u4e2a\u6761\u4ef6\u6765\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u3002\u4e3a\u4e86\u5faa\u73af\u7279\u5b9a\u6b21\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u8ba1\u6570\u5668\u53d8\u91cf\u6765\u8bb0\u5f55\u5faa\u73af\u6b21\u6570\uff0c\u5e76\u5728\u6bcf\u6b21\u5faa\u73af\u4e2d\u66f4\u65b0\u8ba1\u6570\u5668\u3002\u4f8b\u5982\uff0c\u8981\u5faa\u73af5\u6b21\uff0c\u53ef\u4ee5\u521d\u59cb\u5316\u4e00\u4e2a\u8ba1\u6570\u5668\u53d8\u91cf\u4e3a0\uff0c\u7136\u540e\u5728\u5faa\u73af\u4f53\u4e2d\u589e\u52a0\u8ba1\u6570\u5668\uff0c\u76f4\u5230\u8ba1\u6570\u5668\u8fbe\u52305\u4e3a\u6b62\u3002while\u5faa\u73af\u7075\u6d3b\u6027\u66f4\u9ad8\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u907f\u514d\u6b7b\u5faa\u73af\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u7684\u5b9e\u73b0\u7ec6\u8282\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528for\u5faa\u73af\u4e0erange\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0cfor\u5faa\u73af\u901a\u5e38\u7528\u4e8e\u904d\u5386\u4e00\u4e2a\u5e8f\u5217\uff08\u5982\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\u7b49\uff09\u6216\u751f\u6210\u4e00\u4e2a\u5e8f\u5217\u3002\u914d\u5408range\u51fd\u6570\u4f7f\u7528\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u63a7\u5236\u5faa\u73af\u6267\u884c\u7684\u6b21\u6570\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(5):<\/p>\n<p>    print(f&quot;\u8fd9\u662f\u7b2c {i+1} \u6b21\u5faa\u73af&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0crange(5)\u4f1a\u751f\u6210\u4e00\u4e2a\u5e8f\u5217\uff1a0, 1, 2, 3, 4\u3002for\u5faa\u73af\u4f1a\u4f9d\u6b21\u53d6\u51fa\u8fd9\u4e9b\u503c\uff0c\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u53d8\u91cfi\u3002\u5faa\u73af\u4f53\u5185\u7684\u4ee3\u7801\u4f1a\u6267\u884c5\u6b21\uff0ci\u5206\u522b\u4e3a0\u52304\u3002<\/p>\n<\/p>\n<p><h4>2. \u6307\u5b9a\u8d77\u59cb\u503c\u548c\u6b65\u957f<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(1, 10, 2):<\/p>\n<p>    print(f&quot;\u5f53\u524d\u503c\uff1a{i}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0crange(1, 10, 2)\u751f\u6210\u4e00\u4e2a\u5e8f\u5217\uff1a1, 3, 5, 7, 9\u3002\u8d77\u59cb\u503c\u4e3a1\uff0c\u7ec8\u6b62\u503c\u4e3a10\uff08\u4e0d\u5305\u542b10\uff09\uff0c\u6b65\u957f\u4e3a2\u3002for\u5faa\u73af\u4f53\u5185\u7684\u4ee3\u7801\u5c06\u6267\u884c5\u6b21\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528while\u5faa\u73af<\/h3>\n<\/p>\n<p><p>while\u5faa\u73af\u9002\u7528\u4e8e\u9700\u8981\u5728\u5faa\u73af\u8fc7\u7a0b\u4e2d\u6839\u636e\u67d0\u79cd\u6761\u4ef6\u5224\u65ad\u662f\u5426\u7ee7\u7eed\u6267\u884c\u7684\u573a\u666f\u3002\u5b83\u7684\u7075\u6d3b\u6027\u8f83\u9ad8\uff0c\u4f46\u9700\u8981\u624b\u52a8\u63a7\u5236\u5faa\u73af\u6761\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">count = 0<\/p>\n<p>while count &lt; 5:<\/p>\n<p>    print(f&quot;\u8fd9\u662f\u7b2c {count+1} \u6b21\u5faa\u73af&quot;)<\/p>\n<p>    count += 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0ccount\u662f\u4e00\u4e2a\u8ba1\u6570\u5668\uff0c\u521d\u59cb\u503c\u4e3a0\u3002while\u5faa\u73af\u7684\u6761\u4ef6\u662fcount &lt; 5\uff0c\u5faa\u73af\u4f53\u5185\u6bcf\u6b21\u5faa\u73af\u540e\uff0ccount\u589e\u52a01\u3002\u5faa\u73af\u5c06\u6267\u884c5\u6b21\uff0c\u5f53count\u8fbe\u52305\u65f6\uff0c\u6761\u4ef6\u4e0d\u518d\u6ee1\u8db3\uff0c\u5faa\u73af\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><h4>2. \u786e\u4fdd\u5faa\u73af\u5b89\u5168<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528while\u5faa\u73af\u65f6\uff0c\u9700\u8981\u7279\u522b\u6ce8\u610f\u5faa\u73af\u6761\u4ef6\u7684\u8bbe\u7f6e\uff0c\u907f\u514d\u51fa\u73b0\u6b7b\u5faa\u73af\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5e94\u786e\u4fdd\u5faa\u73af\u6761\u4ef6\u80fd\u591f\u5728\u67d0\u4e2a\u65f6\u95f4\u70b9\u88ab\u6ee1\u8db3\uff0c\u4ece\u800c\u4f7f\u5faa\u73af\u5f97\u4ee5\u6b63\u5e38\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9632\u6b62\u6b7b\u5faa\u73af\u7684\u4f8b\u5b50<\/p>\n<p>count = 0<\/p>\n<p>while count &lt; 5:<\/p>\n<p>    print(f&quot;\u8fd9\u662f\u7b2c {count+1} \u6b21\u5faa\u73af&quot;)<\/p>\n<p>    count += 1  # \u786e\u4fdd\u8ba1\u6570\u5668\u5728\u5faa\u73af\u4e2d\u88ab\u66f4\u65b0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u7ed3\u5408break\u548ccontinue\u8bed\u53e5<\/h3>\n<\/p>\n<p><p>\u5728\u5faa\u73af\u4e2d\uff0cbreak\u548ccontinue\u8bed\u53e5\u53ef\u4ee5\u7528\u6765\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n<\/p>\n<p><h4>1. break\u8bed\u53e5<\/h4>\n<\/p>\n<p><p>break\u8bed\u53e5\u7528\u4e8e\u7acb\u5373\u7ec8\u6b62\u5faa\u73af\uff0c\u4e0d\u518d\u6267\u884c\u5faa\u73af\u4f53\u4e2d\u7684\u5176\u4ed6\u4ee3\u7801\uff0c\u5e76\u8df3\u51fa\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(10):<\/p>\n<p>    if i == 5:<\/p>\n<p>        break  # \u5f53i\u7b49\u4e8e5\u65f6\uff0c\u9000\u51fa\u5faa\u73af<\/p>\n<p>    print(f&quot;\u5faa\u73af\u4e2d\uff0ci\u7684\u503c\u4e3a\uff1a{i}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53i\u7b49\u4e8e5\u65f6\uff0cbreak\u8bed\u53e5\u4f7f\u5faa\u73af\u7acb\u5373\u7ed3\u675f\uff0c\u540e\u7eed\u7684\u5faa\u73af\u4e0d\u518d\u6267\u884c\u3002<\/p>\n<\/p>\n<p><h4>2. continue\u8bed\u53e5<\/h4>\n<\/p>\n<p><p>continue\u8bed\u53e5\u7528\u4e8e\u8df3\u8fc7\u5f53\u524d\u5faa\u73af\u4e2d\u7684\u5269\u4f59\u4ee3\u7801\uff0c\u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u6b21\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(5):<\/p>\n<p>    if i == 2:<\/p>\n<p>        continue  # \u8df3\u8fc7i\u7b49\u4e8e2\u7684\u8fd9\u6b21\u5faa\u73af<\/p>\n<p>    print(f&quot;\u5faa\u73af\u4e2d\uff0ci\u7684\u503c\u4e3a\uff1a{i}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53i\u7b49\u4e8e2\u65f6\uff0ccontinue\u8bed\u53e5\u4f1a\u8df3\u8fc7\u8be5\u6b21\u5faa\u73af\u7684\u5269\u4f59\u90e8\u5206\uff0c\u76f4\u63a5\u8fdb\u5165\u4e0b\u4e00\u4e2a\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Python\u7279\u6027\u4f18\u5316\u5faa\u73af<\/h3>\n<\/p>\n<p><p>Python\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u51fd\u6570\u548c\u7279\u6027\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f18\u5316\u5faa\u73af\u7ed3\u6784\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>1. \u5217\u8868\u63a8\u5bfc\u5f0f<\/h4>\n<\/p>\n<p><p>\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u521b\u5efa\u5217\u8868\u7684\u65b9\u5f0f\uff0c\u80fd\u591f\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b9e\u73b0\u5faa\u73af\u548c\u6761\u4ef6\u5224\u65ad\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">squares = [x2 for x in range(5)]<\/p>\n<p>print(squares)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f\u7528\u4e8e\u751f\u62100\u52304\u7684\u5e73\u65b9\u7ec4\u6210\u7684\u5217\u8868\uff1a[0, 1, 4, 9, 16]\u3002<\/p>\n<\/p>\n<p><h4>2. \u679a\u4e3e\u7c7b\u578b\u7684\u4f7f\u7528<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Python\u7684\u5185\u7f6eenumerate\u51fd\u6570\uff0c\u53ef\u4ee5\u5728\u904d\u5386\u5e8f\u5217\u65f6\u83b7\u5f97\u5143\u7d20\u7684\u7d22\u5f15\u548c\u5143\u7d20\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">words = [&quot;Python&quot;, &quot;Java&quot;, &quot;C++&quot;]<\/p>\n<p>for index, word in enumerate(words):<\/p>\n<p>    print(f&quot;\u7b2c{index+1}\u4e2a\u5355\u8bcd\u662f\uff1a{word}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cenumerate\u51fd\u6570\u5c06words\u5217\u8868\u4e2d\u7684\u5143\u7d20\u548c\u7d22\u5f15\u4e00\u8d77\u8fed\u4ee3\uff0c\u4f7f\u5f97\u5728\u5faa\u73af\u4e2d\u540c\u65f6\u53ef\u4ee5\u8bbf\u95ee\u5230\u7d22\u5f15\u548c\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5faa\u73af\u7684\u8bbe\u8ba1\u548c\u5b9e\u73b0\u6709\u591a\u79cd\u65b9\u5f0f\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u5f0f\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u548c\u9ad8\u6548\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u9009\u62e9\u5408\u9002\u7684\u5faa\u73af\u7ed3\u6784<\/strong>\uff1afor\u5faa\u73af\u9002\u7528\u4e8e\u5df2\u77e5\u5faa\u73af\u6b21\u6570\u7684\u60c5\u51b5\uff0cwhile\u5faa\u73af\u9002\u7528\u4e8e\u9700\u8981\u52a8\u6001\u5224\u65ad\u7684\u60c5\u51b5\u3002<\/li>\n<li><strong>\u6ce8\u610f\u5faa\u73af\u6761\u4ef6\u7684\u8bbe\u7f6e<\/strong>\uff1a\u5c24\u5176\u662f\u4f7f\u7528while\u5faa\u73af\u65f6\uff0c\u786e\u4fdd\u6761\u4ef6\u80fd\u591f\u5728\u67d0\u4e2a\u65f6\u95f4\u70b9\u88ab\u6ee1\u8db3\uff0c\u4ee5\u9632\u6b62\u6b7b\u5faa\u73af\u3002<\/li>\n<li><strong>\u638c\u63e1break\u548ccontinue\u8bed\u53e5\u7684\u4f7f\u7528<\/strong>\uff1a\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u8bed\u53e5\u53ef\u4ee5\u4f18\u5316\u5faa\u73af\u903b\u8f91\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u3002<\/li>\n<li><strong>\u5229\u7528Python\u7279\u6027<\/strong>\uff1a\u5982\u5217\u8868\u63a8\u5bfc\u5f0f\u548cenumerate\u51fd\u6570\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6548\u7387\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u7406\u89e3\u8fd9\u4e9b\u57fa\u672c\u6982\u5ff5\u548c\u6280\u5de7\uff0c\u60a8\u53ef\u4ee5\u5728Python\u4e2d\u5b9e\u73b0\u9ad8\u6548\u7684\u5faa\u73af\u63a7\u5236\uff0c\u4ece\u800c\u7f16\u5199\u51fa\u66f4\u52a0\u51fa\u8272\u7684\u7a0b\u5e8f\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u5faa\u73af\u6b21\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u6216<code>while<\/code>\u5faa\u73af\u6765\u8bbe\u7f6e\u7279\u5b9a\u6b21\u6570\u7684\u5faa\u73af\u3002\u5bf9\u4e8e<code>for<\/code>\u5faa\u73af\uff0c\u53ef\u4ee5\u7ed3\u5408<code>range()<\/code>\u51fd\u6570\u6765\u6307\u5b9a\u5faa\u73af\u7684\u6b21\u6570\u3002\u4f8b\u5982\uff0c<code>for i in range(5):<\/code>\u5c06\u4f1a\u5faa\u73af5\u6b21\uff0c<code>i<\/code>\u7684\u503c\u4ece0\u52304\u3002\u4f7f\u7528<code>while<\/code>\u5faa\u73af\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u8ba1\u6570\u5668\u53d8\u91cf\u6765\u63a7\u5236\u5faa\u73af\u6b21\u6570\u3002<\/p>\n<p><strong>Python\u4e2d\u5faa\u73af\u7279\u5b9a\u6b21\u6570\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u4e0e<code>range()<\/code>\u51fd\u6570\u662f\u5faa\u73af\u7279\u5b9a\u6b21\u6570\u7684\u6700\u4f73\u5b9e\u8df5\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u7b80\u6d01\u660e\u4e86\uff0c\u800c\u4e14\u6613\u4e8e\u9605\u8bfb\u548c\u7ef4\u62a4\u3002\u5982\u679c\u9700\u8981\u5728\u5faa\u73af\u4e2d\u6267\u884c\u590d\u6742\u7684\u903b\u8f91\uff0c\u786e\u4fdd\u9002\u65f6\u4f7f\u7528\u51fd\u6570\u5c01\u88c5\u4ee3\u7801\uff0c\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u91cd\u7528\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u4e2d\u65ad\u5faa\u73af\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u6765\u4e2d\u65ad\u5faa\u73af\u3002\u8fd9\u5728\u9700\u8981\u63d0\u524d\u7ed3\u675f\u5faa\u73af\u65f6\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5728\u5faa\u73af\u4e2d\u68c0\u6d4b\u5230\u6ee1\u8db3\u67d0\u4e2a\u6761\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>break<\/code>\u7acb\u5373\u9000\u51fa\u5faa\u73af\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>continue<\/code>\u8bed\u53e5\u53ef\u4ee5\u8df3\u8fc7\u5f53\u524d\u7684\u5faa\u73af\u8fed\u4ee3\uff0c\u76f4\u63a5\u8fdb\u5165\u4e0b\u4e00\u6b21\u5faa\u73af\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5faa\u73af\u7279\u5b9a\u6b21\u6570\u53ef\u4ee5\u4f7f\u7528for\u5faa\u73af\u3001range\u51fd\u6570\u3001while\u5faa\u73af\u7b49\u65b9\u5f0f\u3002for\u5faa\u73af\u901a\u5e38\u7ed3\u5408ran [&hellip;]","protected":false},"author":3,"featured_media":981054,"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\/981045"}],"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=981045"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/981045\/revisions"}],"predecessor-version":[{"id":981057,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/981045\/revisions\/981057"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/981054"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=981045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=981045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=981045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}