{"id":242,"date":"2025-10-10T10:59:36","date_gmt":"2025-10-10T02:59:36","guid":{"rendered":"http:\/\/www.pyteam.cn\/?p=242"},"modified":"2025-10-10T11:01:41","modified_gmt":"2025-10-10T03:01:41","slug":"range%e7%9a%84%e4%b8%89%e7%a7%8d%e7%94%a8%e6%b3%95%e4%b8%89-7-4","status":"publish","type":"post","link":"http:\/\/www.pyteam.cn\/index.php\/2025\/10\/10\/range%e7%9a%84%e4%b8%89%e7%a7%8d%e7%94%a8%e6%b3%95%e4%b8%89-7-4\/","title":{"rendered":"range()\u7684\u4e09\u79cd\u7528\u6cd5\u4e09 7.5"},"content":{"rendered":"\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:clamp(18px, 1.125rem, 27px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#90A4AE;--cbp-line-number-width:calc(1 * 0.6 * 1.125rem);line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#ededed;color:#8198a3\">Python<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#90A4AE;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly># \u751f\u6210\u5e8f\u5217\uff1a1, 3, 5, 7, 9 (\u4ece1\u5f00\u59cb\uff0c\u6b65\u957f\u4e3a2)\nfor i in range(1, 10, 2):\n    print(i, end=' ')\n# \u8f93\u51fa\uff1a1 3 5 7 9\n\n# \u751f\u6210\u9012\u51cf\u5e8f\u5217\uff1a5, 4, 3, 2, 1\nfor i in range(5, 0, -1):\n    print(i, end=' ')\n# \u8f93\u51fa\uff1a5 4 3 2 1<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-lighter\" style=\"background-color: #FAFAFA\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># \u751f\u6210\u5e8f\u5217\uff1a1, 3, 5, 7, 9 (\u4ece1\u5f00\u59cb\uff0c\u6b65\u957f\u4e3a2)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #39ADB5; font-style: italic\">for<\/span><span style=\"color: #90A4AE\"> i <\/span><span style=\"color: #39ADB5; font-style: italic\">in<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #6182B8\">range<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #F76D47\">1<\/span><span style=\"color: #39ADB5\">,<\/span><span style=\"color: #6182B8\"> <\/span><span style=\"color: #F76D47\">10<\/span><span style=\"color: #39ADB5\">,<\/span><span style=\"color: #6182B8\"> <\/span><span style=\"color: #F76D47\">2<\/span><span style=\"color: #39ADB5\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #6182B8\">print<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #6182B8\">i<\/span><span style=\"color: #39ADB5\">,<\/span><span style=\"color: #6182B8\"> <\/span><span style=\"color: #90A4AE; font-style: italic\">end<\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #39ADB5\">&#39;<\/span><span style=\"color: #91B859\"> <\/span><span style=\"color: #39ADB5\">&#39;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># \u8f93\u51fa\uff1a1 3 5 7 9<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># \u751f\u6210\u9012\u51cf\u5e8f\u5217\uff1a5, 4, 3, 2, 1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #39ADB5; font-style: italic\">for<\/span><span style=\"color: #90A4AE\"> i <\/span><span style=\"color: #39ADB5; font-style: italic\">in<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #6182B8\">range<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #F76D47\">5<\/span><span style=\"color: #39ADB5\">,<\/span><span style=\"color: #6182B8\"> <\/span><span style=\"color: #F76D47\">0<\/span><span style=\"color: #39ADB5\">,<\/span><span style=\"color: #6182B8\"> <\/span><span style=\"color: #39ADB5\">-<\/span><span style=\"color: #F76D47\">1<\/span><span style=\"color: #39ADB5\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #6182B8\">print<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #6182B8\">i<\/span><span style=\"color: #39ADB5\">,<\/span><span style=\"color: #6182B8\"> <\/span><span style=\"color: #90A4AE; font-style: italic\">end<\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #39ADB5\">&#39;<\/span><span style=\"color: #91B859\"> <\/span><span style=\"color: #39ADB5\">&#39;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># \u8f93\u51fa\uff1a5 4 3 2 1<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":120,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,5],"tags":[],"class_list":["post-242","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-for","category-5"],"views":167,"_links":{"self":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/comments?post=242"}],"version-history":[{"count":2,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":249,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/242\/revisions\/249"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media\/120"}],"wp:attachment":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media?parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/categories?post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/tags?post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}