{"id":146,"date":"2023-03-09T15:44:00","date_gmt":"2023-03-09T06:44:00","guid":{"rendered":"https:\/\/www.hongomcc.net\/?p=146"},"modified":"2023-12-14T10:46:30","modified_gmt":"2023-12-14T01:46:30","slug":"%e7%b5%90%e5%b1%80_for_i_in_range_%e3%81%a3%e3%81%a6%e3%81%aa%e3%81%ab","status":"publish","type":"post","link":"https:\/\/www.hongomcc.net\/blogs\/2023\/03\/09\/%e7%b5%90%e5%b1%80_for_i_in_range_%e3%81%a3%e3%81%a6%e3%81%aa%e3%81%ab\/","title":{"rendered":"\u7d50\u5c40 for i in range() \u3063\u3066\u306a\u306b\uff1f"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u306f\u3058\u3081\u306b<\/h1>\n\n\n\n<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9ad8\u6821\u90e8\u9577\u3067\u3059\u3002<br>python\u6b74\u3060\u3044\u305f\u30443\u30f6\u6708\u306e\u521d\u5fc3\u8005\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3055\u3066\u30012023\u306e3\u6708\u306b\u4eca\u5e74\u5ea6\u304b\u3089\u65b0\u8ab2\u7a0b\u3067\u65b0\u3057\u304f\u52a0\u308f\u3063\u305f\u60c5\u5831I\u306e\u5b66\u671f\u672b\u30c6\u30b9\u30c8\u3092\u53d7\u3051\u305f\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3053\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u304c\uff1a<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>for i in range(0, 6, 3):\n    i = i + 3\n    print(i)<\/code><\/pre><\/div>\n\n\n\n<p>\u50d5\u306f\u305d\u306e\u6642\u5358\u7d14\u306b<\/p>\n\n\n\n<p>\u300c\u306a\u308b\u307b\u3069\u306a\uff01\u3058\u3083\u3042\u3053\u308c\u3092C++\u3063\u307d\u304f\u76f4\u3059\u3068\u3001\u300d<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>for(int i = 0; i &lt; 6; i += 3){\n    i += 3;\n    std::cout &lt;&lt; i &lt;&lt; std::endl;\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u300c\u306b\u306a\u308b\u304b\u3089\u20262\u56de\u76ee\u306e\u30eb\u30fc\u30d7\u306e\u521d\u3081\u3067\u306f<code>i<\/code>\u306b<code>6<\/code>\u304c\u4ee3\u5165\u3055\u308c\u3066\u3044\u308b\u304b\u3089\u5b9f\u884c\u3055\u308c\u305a\u3001\u51fa\u529b\u7d50\u679c\u306f<code>3<\/code>\u3060\u3051\u306b\u9055\u3044\u306a\u3044\uff01\uff01\u300d<\/p>\n\n\n\n<p>\u3068\u8003\u3048\u305f\u306e\u3067\u3059\u3088\u3002\u305d\u3057\u3066\u306a\u3093\u3068\u7b54\u3048\u306f<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>3\n6<\/code><\/pre><\/div>\n\n\n\n<p>\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f\uff1f<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">range<\/h1>\n\n\n\n<p><code>range<\/code> \u306fPython\u306e\u7d44\u307f\u8fbc\u307f\u578b\u306e\u4e00\u7a2e\u3089\u3057\u3044\u3002<\/p>\n\n\n\n<p>\u521d\u671f\u5316\u306f<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>range(stop)\nrange(start, stop[, step])<\/code><\/pre><\/div>\n\n\n\n<p>\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<a href=\"https:\/\/docs.python.org\/ja\/3\/library\/stdtypes.html#range\">^1<\/a>\u66f0\u304f\u3001<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>step \u304c\u6b63\u306e\u5834\u5408\u3001range r \u306e\u5185\u5bb9\u306f\u5f0f r[i] = start + step*i \u3067\u6c7a\u5b9a\u3055\u308c\u307e\u3059\u3002\u3053\u3053\u3067\u3001 i &gt;= 0 \u304b\u3064 r[i] &lt; stop \u3067\u3059\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u3069\u3046\u3084\u3089<code>range<\/code>\u306f<code>list<\/code>\u306e\u3088\u3046\u306a\u6319\u52d5\u3059\u308b\u3089\u3057\u3044\u3002\u8a66\u3057\u306b<code>list<\/code>\u578b\u306b\u30ad\u30e3\u30b9\u30c8\u3057\u3066\u307f\u308b\u3068\u3001<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>list(range(10))  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nlist(range(0, 6, 3))  # [0, 3]<\/code><\/pre><\/div>\n\n\n\n<p>\u3064\u307e\u308a<code>for i in range(0, 6, 3)<\/code>\u3068\u3044\u3046\u306e\u306f<code>for i in [0,3]<\/code>\u3068\u540c\u3058\u6319\u52d5\u3092\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3060\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>for i in [0, 3]:\n  i = i + 3\n  print(i)\n#3\n#6<\/code><\/pre><\/div>\n\n\n\n<p>\u3064\u307e\u308b\u3068\u3053\u308d\u51e6\u7406\u306e\u7d42\u308f\u308a\u3067\u30ab\u30a6\u30f3\u30bf\u5909\u6570<code>i<\/code>\u306b3\u304c\u305f\u3055\u308c\u3066\u3001<code>i<\/code>\u304c0\u3001\u3082\u3057\u304f\u306f3\u3067\u3042\u3063\u305f\u5834\u5408\u306f\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u3068\u3044\u3046\u3053\u3068\uff1f\u3060\u3068\u8003\u3048\u3066\u3044\u305f\u306e\u3060\u304c\u3001\u3069\u3046\u3084\u3089\u305d\u3046\u3067\u306f\u306a\u3044\u3089\u3057\u3044\u2026\u3080\u3057\u308d\u305d\u306e\u3088\u3046\u306b\u66f8\u304d\u305f\u3044\u306e\u306a\u3089<code>while<\/code>\u6587\u3067\u66f8\u304f\u3079\u304d\u3060\u3057\u2026\u2026<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">for \u3063\u3066\u306a\u3093\u3060\u308d\u3046<\/h1>\n\n\n\n<p>\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304b\u3089\u306e\u5f15\u7528<a href=\"https:\/\/docs.python.org\/ja\/3\/reference\/compound_stmts.html#the-for-statement\">^2<\/a>:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>for_stmt ::=  &quot;for&quot; target_list &quot;in&quot; starred_list &quot;:&quot; suite\n              [&quot;else&quot; &quot;:&quot; suite]<\/code><\/pre><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The starred_list expression is evaluated once;<br>An iterator is created for that iterable.<br>The first item provided by the iterator is then assigned to the target list<br>for \u30eb\u30fc\u30d7\u306f\u30bf\u30fc\u30b2\u30c3\u30c8\u30ea\u30b9\u30c8\u5185\u306e\u5909\u6570\u3078\u306e\u4ee3\u5165\u3092\u884c\u3044\u307e\u3059\u3002 \u3053\u308c\u306b\u3088\u308a\u3001for \u30eb\u30fc\u30d7\u5185\u3082\u542b\u3081\u3066\u3001\u305d\u308c\u4ee5\u524d\u306e\u5168\u3066\u306e\u4ee3\u5165\u306f\u4e0a\u66f8\u304d\u3055\u308c\u307e\u3059:<\/p>\n<\/blockquote>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>for i in range(10):\n    print(i)\n    i = 5             # this will not affect the for-loop\n                      # because i will be overwritten with the next\n                      # index in the range<\/code><\/pre><\/div>\n\n\n\n<p>\u3064\u307e\u308a\u3001\u307e\u305a<code>range(0, 6, 3)<\/code>\u306f<code>for<\/code>\u30eb\u30fc\u30d7\u304c\u59cb\u307e\u308b\u3068\u304d\u306b<strong>1\u5ea6<\/strong>\u3060\u3051\u8a55\u4fa1\u3055\u308c\u3066\u3001\u305d\u306e\u3042\u3068\u306f\u30a4\u30c6\u30ec\u30fc\u30bf\u3067\u3042\u308b<code>[0, 3]<\/code>\u304c\u751f\u6210\u3055\u308c\u3001\u6700\u521d\u306e<code>i<\/code>\u306b\u305d\u306e\u6700\u521d\u306e\u8981\u7d20\u304c\u4ee3\u5165\u3055\u308c\u308b\u3068\u3044\u3046\u3002<\/p>\n\n\n\n<p>\u305d\u3057\u3066<code>suite<\/code>\u306e\u7d42\u308f\u308a\u306b\u306f<code>i<\/code>\u306b\u52a0\u7b97\u3055\u308c\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u6b21\u306e\u30a4\u30c6\u30ec\u30fc\u30bf\u306e\u8981\u7d20\u304c\u4ee3\u5165\u3055\u308c\u308b\u3002\u3064\u307e\u308a\u3001<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>for i in range(0, 6, 3):\n    i = i + 3\n    print(i)<\/code><\/pre><\/div>\n\n\n\n<p>\u306b\u304a\u3044\u3066\u306f\u3001\u4e00\u56de\u76ee\u306e\u30eb\u30fc\u30d7\u3067<code>i<\/code>\u306b<code>0<\/code>\u304c\u4ee3\u5165\u3055\u308c\u3066<code>3<\/code>\u304c\u8db3\u3055\u308c\u3066\u305d\u308c\u3092\u8868\u793a\u3057\u3001\u4e8c\u56de\u76ee\u306e\u30eb\u30fc\u30d7\u3067<code>for<\/code>\u306b\u3088\u3063\u3066<code>i<\/code>\u306b<code>3<\/code>\u304c\u4ee3\u5165\u3055\u308c\u3066\u305d\u308c\u306b<code>3<\/code>\u304c\u8db3\u3055\u308c\u3066<code>6<\/code>\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u3002<\/p>\n\n\n\n<p>\u306a\u308b\u307b\u3069\u306a\u30fc\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h1>\n\n\n\n<p><code>for<\/code>\u6587\u306f\u30ab\u30a6\u30f3\u30bf\u5909\u6570\u306b<code>in<\/code>\u306e\u5f8c\u306b\u8a18\u8ff0\u3057\u305f\u30a4\u30c6\u30e9\u30d6\u30eb\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u8981\u7d20\u3092\u4e00\u3064\u305a\u3064\u4ee3\u5165\u3059\u308b\u3002\u30ab\u30a6\u30f3\u30bf\u5909\u6570\u306f\u30eb\u30fc\u30d7\u5185\u3067\u5024\u3092\u4ee3\u5165\u3057\u3066\u3082\u3001\u30eb\u30fc\u30d7\u306e\u59cb\u3081\u3067\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u6b21\u306e\u8981\u7d20\u304c\u4ee3\u5165\u3055\u308c\u308b\u3002\u3060\u304b\u3089<code>range<\/code>\u306e\u4ee3\u308f\u308a\u306b<code>list<\/code>\u578b\u3092\u5165\u308c\u3066\u305d\u308c\u305d\u308c\u306e\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3059\u3068\u3044\u3046\u82b8\u5f53\u304c\u53ef\u80fd\u306b\u306a\u308b\u306e\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p>\u3058\u3083\u3042\u305d\u308c<code>foreach<\/code>\u3058\u3083\u306d\u3047\u304b\uff01\uff01\uff01<a href=\"\u8abf\u3079\u305f\u3089\u601d\u3063\u305f\u3088\u308a`foreach`\u6587\u306b`for`\u3092\u305d\u306e\u307e\u307e\u4f7f\u3063\u3066\u3044\u308b\u3082\u306e\u3082\u591a\u304f\u3066\u3073\u3063\u304f\u308a\u3001C++\u3067\u3082\u305d\u3046\u3060\u3063\u305f\u306a\u3093\u3066\u2026\u81ea\u79f0\u30d7\u30ed\u30b0\u30e9\u30de\u3067\u3042\u308b\u3053\u3068\u304c\u30d0\u30ec\u3066\u3057\u307e\u3046\u2026\">^3<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u3055\u3044\u3054\u306b<\/h1>\n\n\n\n<p>\u30e9\u30e0\u30c0\u5f0f\u697d\u3057\u3044\uff01\uff01\uff01<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u3053\u3093\u306b\u3061\u306f\u3001\u9ad8\u6821\u90e8\u9577\u3067\u3059\u3002python\u6b74\u3060\u3044\u305f\u30443\u30f6\u6708\u306e\u521d\u5fc3\u8005\u3067\u3059\u3002 \u3055\u3066\u30012023\u306e3\u6708\u306b\u4eca\u5e74\u5ea6\u304b\u3089\u65b0\u8ab2\u7a0b\u3067\u65b0\u3057\u304f\u52a0\u308f\u3063\u305f\u60c5\u5831I\u306e\u5b66\u671f\u672b\u30c6\u30b9\u30c8\u3092\u53d7\u3051\u305f\u306e\u3067\u3059\u3002 \u305d\u3053\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u304c\uff1a \u50d5\u306f\u305d\u306e\u6642\u5358\u7d14\u306b [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":314,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[11,15],"tags":[13,14,12],"class_list":{"0":"post-146","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-python","8":"category-15","9":"tag-for","11":"tag-python"},"_links":{"self":[{"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":9,"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":312,"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/posts\/146\/revisions\/312"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/media\/314"}],"wp:attachment":[{"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongomcc.net\/blogs\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}