{"id":940540,"date":"2024-12-26T21:01:59","date_gmt":"2024-12-26T13:01:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/940540.html"},"modified":"2024-12-26T21:02:01","modified_gmt":"2024-12-26T13:02:01","slug":"python%e5%a6%82%e4%bd%95%e7%94%a8range","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/940540.html","title":{"rendered":"python\u5982\u4f55\u7528range"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075133\/6f36c05d-d44a-44e8-a7c8-46d2d7faec50.webp\" alt=\"python\u5982\u4f55\u7528range\" \/><\/p>\n<p><p> \u5728Python\u4e2d\uff0c<strong><code>range()<\/code>\u51fd\u6570\u7528\u4e8e\u751f\u6210\u4e00\u4e2a\u6574\u6570\u5e8f\u5217\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u5faa\u73af\u8fed\u4ee3\u3001\u521b\u5efa\u5217\u8868\u4ee5\u53ca\u5176\u4ed6\u9700\u8981\u6574\u6570\u5e8f\u5217\u7684\u573a\u5408<\/strong>\u3002<code>range()<\/code>\u51fd\u6570\u4f7f\u7528\u7b80\u5355\uff0c\u4f46\u529f\u80fd\u5f3a\u5927\uff0c\u4e3b\u8981\u6709\u4e09\u79cd\u4f7f\u7528\u65b9\u5f0f\uff1a\u63d0\u4f9b\u4e00\u4e2a\u505c\u6b62\u503c\u3001\u63d0\u4f9b\u8d77\u59cb\u548c\u505c\u6b62\u503c\u3001\u4ee5\u53ca\u63d0\u4f9b\u8d77\u59cb\u3001\u505c\u6b62\u548c\u6b65\u957f\u503c\u3002\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c<code>range()<\/code>\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u5faa\u73af\u548c\u8fed\u4ee3\uff0c\u4f7f\u4ee3\u7801\u66f4\u4e3a\u7b80\u6d01\u548c\u9ad8\u6548\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd<code>range()<\/code>\u7684\u4f7f\u7528\u65b9\u6cd5\u53ca\u5176\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u57fa\u672c\u7528\u6cd5<\/p>\n<\/p>\n<p><p><code>range()<\/code>\u51fd\u6570\u6709\u4e09\u79cd\u5e38\u7528\u7684\u8c03\u7528\u65b9\u5f0f\uff1a\u53ea\u63d0\u4f9b\u505c\u6b62\u503c\u3001\u63d0\u4f9b\u8d77\u59cb\u548c\u505c\u6b62\u503c\u3001\u4ee5\u53ca\u63d0\u4f9b\u8d77\u59cb\u3001\u505c\u6b62\u548c\u6b65\u957f\u503c\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u53ea\u63d0\u4f9b\u505c\u6b62\u503c<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53\u53ea\u7ed9\u51fa\u4e00\u4e2a\u53c2\u6570\u65f6\uff0c\u8fd9\u4e2a\u53c2\u6570\u88ab\u5f53\u4f5c\u662f\u505c\u6b62\u503c\uff0c\u5e8f\u5217\u4ece0\u5f00\u59cb\uff0c\u5230\u505c\u6b62\u503c\uff08\u4e0d\u5305\u62ec\u505c\u6b62\u503c\uff09\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(5):<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa0\u52304\uff0c\u56e0\u4e3a<code>range(5)<\/code>\u751f\u6210\u7684\u5e8f\u5217\u662f0, 1, 2, 3, 4\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u63d0\u4f9b\u8d77\u59cb\u548c\u505c\u6b62\u503c<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53\u63d0\u4f9b\u4e24\u4e2a\u53c2\u6570\u65f6\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8d77\u59cb\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u505c\u6b62\u503c\u3002\u5e8f\u5217\u4ece\u8d77\u59cb\u503c\u5f00\u59cb\uff0c\u5230\u505c\u6b62\u503c\uff08\u4e0d\u5305\u62ec\u505c\u6b62\u503c\uff09\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(2, 6):<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa2\u52305\uff0c\u56e0\u4e3a<code>range(2, 6)<\/code>\u751f\u6210\u7684\u5e8f\u5217\u662f2, 3, 4, 5\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u63d0\u4f9b\u8d77\u59cb\u3001\u505c\u6b62\u548c\u6b65\u957f\u503c<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53\u63d0\u4f9b\u4e09\u4e2a\u53c2\u6570\u65f6\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8d77\u59cb\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u505c\u6b62\u503c\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u6b65\u957f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(1, 10, 2):<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa1, 3, 5, 7, 9\uff0c\u56e0\u4e3a<code>range(1, 10, 2)<\/code>\u751f\u6210\u7684\u5e8f\u5217\u662f\u4ece1\u5f00\u59cb\uff0c\u6b65\u957f\u4e3a2\uff0c\u523010\uff08\u4e0d\u5305\u62ec10\uff09\u4e3a\u6b62\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5e94\u7528\u573a\u666f<\/p>\n<\/p>\n<ol>\n<li><strong>\u5faa\u73af\u8fed\u4ee3<\/strong><\/li>\n<\/ol>\n<p><p><code>range()<\/code>\u6700\u5e38\u89c1\u7684\u7528\u9014\u662f\u4e0e<code>for<\/code>\u5faa\u73af\u7ed3\u5408\u4f7f\u7528\uff0c\u8fdb\u884c\u8fed\u4ee3\u3002\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u751f\u6210\u4e00\u4e2a\u6574\u6570\u5e8f\u5217\uff0c\u7528\u4e8e\u904d\u5386\u67d0\u4e9b\u6570\u636e\u7ed3\u6784\u6216\u8005\u8fdb\u884c\u91cd\u590d\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6253\u5370\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u53ca\u5176\u7d22\u5f15<\/p>\n<p>my_list = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;]<\/p>\n<p>for i in range(len(my_list)):<\/p>\n<p>    print(f&quot;Index: {i}, Element: {my_list[i]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u521b\u5efa\u5217\u8868<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Python 3\u4e2d\uff0c<code>range()<\/code>\u751f\u6210\u7684\u662f\u4e00\u4e2a<code>range<\/code>\u5bf9\u8c61\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528<code>list()<\/code>\u51fd\u6570\u5c06\u5176\u8f6c\u6362\u4e3a\u4e00\u4e2a\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_list = list(range(5))<\/p>\n<p>print(num_list)  # \u8f93\u51fa: [0, 1, 2, 3, 4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u63a7\u5236\u5faa\u73af\u6b65\u957f<\/strong><\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u6307\u5b9a\u6b65\u957f\uff0c<code>range()<\/code>\u53ef\u4ee5\u7528\u6765\u63a7\u5236\u5faa\u73af\u4e2d\u6570\u5b57\u7684\u589e\u51cf\u3002\u4f8b\u5982\uff0c\u53cd\u5411\u904d\u5386\u4e00\u4e2a\u5e8f\u5217\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(10, 0, -1):<\/p>\n<p>    print(i)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa10\u52301\u7684\u6570\u5b57\uff0c\u6b65\u957f\u4e3a-1\uff0c\u5373\u5012\u5e8f\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<ol>\n<li><strong><code>range<\/code>\u5bf9\u8c61\u7684\u6027\u8d28<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Python 3\u4e2d\uff0c<code>range<\/code>\u5bf9\u8c61\u4e0d\u662f\u5217\u8868\uff0c\u800c\u662f\u4e00\u4e2a\u4e0d\u53ef\u53d8\u7684\u5e8f\u5217\u7c7b\u578b\u3002\u8fd9\u4f7f\u5f97<code>range<\/code>\u5bf9\u8c61\u672c\u8eab\u662f\u60f0\u6027\u6c42\u503c\u7684\uff0c\u53ea\u6709\u5728\u9700\u8981\u65f6\u624d\u751f\u6210\u6240\u9700\u7684\u6570\u5b57\uff0c\u8fd9\u5bf9\u4e8e\u5904\u7406\u5927\u578b\u5e8f\u5217\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5185\u5b58\u6548\u7387<\/strong><\/li>\n<\/ol>\n<p><p>\u7531\u4e8e<code>range<\/code>\u5bf9\u8c61\u4e0d\u5b9e\u9645\u751f\u6210\u6240\u6709\u6570\u5b57\uff0c\u800c\u662f\u5728\u9700\u8981\u65f6\u751f\u6210\u6570\u5b57\uff0c\u56e0\u6b64\u5b83\u6bd4\u5217\u8868\u66f4\u4e3a\u5185\u5b58\u9ad8\u6548\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u8303\u56f4\u7684\u6570\u5b57\u65f6\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6b65\u957f\u4e3a0\u7684\u60c5\u51b5<\/strong><\/li>\n<\/ol>\n<p><p>\u5982\u679c\u6b65\u957f\u4e3a0\uff0c<code>range()<\/code>\u51fd\u6570\u4f1a\u5f15\u53d1<code>ValueError<\/code>\uff0c\u56e0\u4e3a\u8fd9\u6ca1\u6709\u610f\u4e49\uff0c\u6b65\u957f\u4e3a0\u610f\u5473\u7740\u6ca1\u6709\u524d\u8fdb\u65b9\u5411\uff0c\u65e0\u6cd5\u751f\u6210\u5e8f\u5217\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u8fdb\u9636\u7528\u6cd5<\/p>\n<\/p>\n<ol>\n<li><strong>\u7ed3\u5408<code>enumerate()<\/code><\/strong><\/li>\n<\/ol>\n<p><p><code>enumerate()<\/code>\u51fd\u6570\u53ef\u4ee5\u5728\u904d\u5386\u5e8f\u5217\u65f6\u540c\u65f6\u83b7\u53d6\u5143\u7d20\u7684\u7d22\u5f15\u548c\u503c\uff0c\u7ed3\u5408<code>range()<\/code>\u4f7f\u7528\uff0c\u53ef\u4ee5\u66f4\u52a0\u7075\u6d3b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;]<\/p>\n<p>for index, value in enumerate(my_list):<\/p>\n<p>    print(f&quot;Index: {index}, Value: {value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4e0e\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u7ed3\u5408<\/strong><\/li>\n<\/ol>\n<p><p><code>range()<\/code>\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u7d22\u5f15\uff0c\u4ece\u800c\u904d\u5386\u5176\u4ed6\u6570\u636e\u7ed3\u6784\uff0c\u5982\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;hello&quot;<\/p>\n<p>for i in range(len(my_string)):<\/p>\n<p>    print(my_string[i])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6761\u4ef6\u63a7\u5236<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5faa\u73af\u4e2d\u4f7f\u7528<code>range()<\/code>\u65f6\uff0c\u7ed3\u5408\u6761\u4ef6\u8bed\u53e5\u53ef\u4ee5\u5b9e\u73b0\u590d\u6742\u7684\u63a7\u5236\u903b\u8f91\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for i in range(10):<\/p>\n<p>    if i % 2 == 0:<\/p>\n<p>        print(f&quot;{i} is even&quot;)<\/p>\n<p>    else:<\/p>\n<p>        print(f&quot;{i} is odd&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u5b9e\u9645\u6848\u4f8b\u5206\u6790<\/p>\n<\/p>\n<ol>\n<li><strong>\u6570\u636e\u5904\u7406<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u4e2d\uff0c<code>range()<\/code>\u53ef\u4ee5\u7528\u4e8e\u5faa\u73af\u5904\u7406\u6570\u636e\u96c6\u4e2d\u7684\u6bcf\u4e00\u9879\u3002\u4f8b\u5982\uff0c\u5728\u5904\u7406\u8868\u683c\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u7528<code>range()<\/code>\u751f\u6210\u7d22\u5f15\u6765\u8bbf\u95ee\u6bcf\u4e00\u884c\u6216\u5217\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<p>for i in range(len(data)):<\/p>\n<p>    row_sum = sum(data[i])<\/p>\n<p>    print(f&quot;Sum of row {i}: {row_sum}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7ed8\u56fe<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u53ef\u89c6\u5316\u4e2d\uff0c<code>range()<\/code>\u5e38\u7528\u4e8e\u751f\u6210\u7ed8\u56fe\u7684\u5750\u6807\u503c\u3002\u4f8b\u5982\uff0c\u5728\u7ed8\u5236\u7b80\u5355\u7684\u51fd\u6570\u56fe\u50cf\u65f6\uff0c\u4f7f\u7528<code>range()<\/code>\u751f\u6210x\u8f74\u7684\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>x_values = range(-10, 11)<\/p>\n<p>y_values = [x2 for x in x_values]<\/p>\n<p>plt.plot(x_values, y_values)<\/p>\n<p>plt.title(&quot;y = x^2&quot;)<\/p>\n<p>plt.xlabel(&quot;x&quot;)<\/p>\n<p>plt.ylabel(&quot;y&quot;)<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6e38\u620f\u5f00\u53d1<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u6e38\u620f\u5f00\u53d1\u4e2d\uff0c<code>range()<\/code>\u53ef\u7528\u4e8e\u751f\u6210\u6e38\u620f\u5bf9\u8c61\u7684\u4f4d\u7f6e\u3001\u63a7\u5236\u6e38\u620f\u5faa\u73af\u7b49\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u7b80\u5355\u7684\u7f51\u683c\u6e38\u620f\u4e2d\uff0c\u53ef\u4ee5\u7528<code>range()<\/code>\u751f\u6210\u7f51\u683c\u7684\u5750\u6807\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">grid_size = 5<\/p>\n<p>for x in range(grid_size):<\/p>\n<p>    for y in range(grid_size):<\/p>\n<p>        print(f&quot;Grid position: ({x}, {y})&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u5185\u5bb9\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c<code>range()<\/code>\u51fd\u6570\u5728Python\u4e2d\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u4e14\u7075\u6d3b\u7684\u5de5\u5177\u3002\u5b83\u4e0d\u4ec5\u7b80\u5316\u4e86\u5faa\u73af\u7684\u7f16\u5199\uff0c\u8fd8\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6548\u7387\u3002\u65e0\u8bba\u662f\u5728\u6570\u636e\u5904\u7406\u3001\u79d1\u5b66\u8ba1\u7b97\uff0c\u8fd8\u662f\u6e38\u620f\u5f00\u53d1\u4e2d\uff0c<code>range()<\/code>\u90fd\u80fd\u53d1\u6325\u91cd\u8981\u4f5c\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528range\u51fd\u6570\u751f\u6210\u5e8f\u5217\uff1f<\/strong><br \/>range\u51fd\u6570\u7528\u4e8e\u751f\u6210\u4e00\u4e2a\u6574\u6570\u5e8f\u5217\uff0c\u975e\u5e38\u9002\u5408\u5728\u5faa\u73af\u4e2d\u4f7f\u7528\u3002\u8c03\u7528\u5f62\u5f0f\u4e3a<code>range(start, stop, step)<\/code>\uff0c\u5176\u4e2dstart\u662f\u5e8f\u5217\u7684\u8d77\u59cb\u503c\uff0cstop\u662f\u7ed3\u675f\u503c\uff08\u4e0d\u5305\u62ec\uff09\uff0cstep\u662f\u6b65\u957f\u3002\u5982\u679c\u53ea\u63d0\u4f9bstop\uff0c\u9ed8\u8ba4\u4ece0\u5f00\u59cb\uff0c\u6b65\u957f\u4e3a1\u3002\u6bd4\u5982\uff0c<code>range(5)<\/code>\u4f1a\u751f\u62100\u52304\u7684\u5e8f\u5217\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u4f7f\u7528range\u65f6\uff0c\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u9700\u8981\u907f\u514d\uff1f<\/strong><br \/>\u4f7f\u7528range\u65f6\uff0c\u5e38\u89c1\u9519\u8bef\u5305\u62ec\u5fd8\u8bb0\u5b9a\u4e49start\u6216step\u53c2\u6570\uff0c\u5bfc\u81f4\u751f\u6210\u7684\u5e8f\u5217\u4e0d\u7b26\u5408\u9884\u671f\uff1b\u4f7f\u7528\u8d1f\u6570\u4f5c\u4e3astep\u65f6\uff0cstop\u5fc5\u987b\u5c0f\u4e8estart\uff0c\u5426\u5219\u5c06\u5f97\u5230\u4e00\u4e2a\u7a7a\u5e8f\u5217\u3002\u6b64\u5916\uff0c\u786e\u4fddstop\u53c2\u6570\u4e3a\u6574\u6570\u7c7b\u578b\uff0c\u907f\u514d\u56e0\u7c7b\u578b\u9519\u8bef\u5bfc\u81f4\u4ee3\u7801\u8fd0\u884c\u5931\u8d25\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728for\u5faa\u73af\u4e2d\u6709\u6548\u5730\u4f7f\u7528range\uff1f<\/strong><br \/>\u5728for\u5faa\u73af\u4e2d\uff0crange\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u904d\u5386\u7279\u5b9a\u6570\u91cf\u7684\u8fed\u4ee3\u3002\u4f7f\u7528<code>for i in range(n):<\/code>\u53ef\u4ee5\u6267\u884cn\u6b21\u5faa\u73af\uff0c\u5176\u4e2di\u4f1a\u4ece0\u9010\u6e10\u589e\u52a0\u5230n-1\u3002\u5982\u679c\u9700\u8981\u904d\u5386\u7279\u5b9a\u8303\u56f4\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u901a\u8fc7<code>for i in range(start, stop, step):<\/code>\u6765\u5b9a\u4e49\u5faa\u73af\u7684\u8d77\u59cb\u70b9\u3001\u7ec8\u6b62\u70b9\u548c\u6b65\u957f\uff0c\u4ece\u800c\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u63a7\u5236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0crange()\u51fd\u6570\u7528\u4e8e\u751f\u6210\u4e00\u4e2a\u6574\u6570\u5e8f\u5217\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u5faa\u73af\u8fed\u4ee3\u3001\u521b\u5efa\u5217\u8868\u4ee5\u53ca\u5176\u4ed6\u9700\u8981\u6574\u6570\u5e8f\u5217\u7684\u573a [&hellip;]","protected":false},"author":3,"featured_media":940542,"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\/940540"}],"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=940540"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/940540\/revisions"}],"predecessor-version":[{"id":940544,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/940540\/revisions\/940544"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/940542"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=940540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=940540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=940540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}