[{"data":1,"prerenderedAt":2337},["ShallowReactive",2],{"doc-\u002Flearn\u002Fpython-for-loops-explained":3},{"id":4,"title":5,"body":6,"description":2330,"extension":2331,"meta":2332,"navigation":117,"path":2333,"seo":2334,"stem":2335,"__hash__":2336},"content\u002Flearn\u002Fpython-for-loops-explained.md","Python for Loops Explained",{"type":7,"value":8,"toc":2289},"minimark",[9,13,26,32,48,53,154,157,177,183,187,192,195,217,223,227,230,260,263,289,292,295,339,341,361,364,377,386,390,393,463,465,485,488,515,518,527,530,537,541,547,581,583,611,623,626,667,669,692,695,720,723,749,756,760,765,768,817,819,839,843,846,934,936,951,957,1047,1049,1067,1070,1078,1082,1085,1090,1141,1143,1164,1174,1177,1182,1230,1232,1253,1265,1272,1276,1285,1291,1344,1346,1368,1377,1445,1447,1455,1458,1462,1468,1472,1478,1481,1518,1521,1558,1562,1565,1567,1605,1607,1643,1650,1657,1662,1692,1694,1718,1722,1725,1793,1795,1817,1823,1827,1830,1899,1910,1914,1919,1930,1935,1943,1946,1961,1968,1972,1975,1979,1994,1997,2001,2023,2026,2033,2058,2060,2089,2093,2115,2118,2122,2138,2144,2147,2174,2181,2185,2189,2194,2198,2204,2208,2222,2226,2234,2238,2243,2247,2275,2285],[10,11,5],"h1",{"id":12},"python-for-loops-explained",[14,15,16,17,21,22,25],"p",{},"A ",[18,19,20],"code",{},"for"," loop in Python lets you repeat code once for each item in a group of values. It is one of the most useful tools for beginners because it makes it easy to work through lists, strings, dictionaries, and ",[18,23,24],{},"range()"," values without manually managing positions.",[14,27,28,29,31],{},"You will use ",[18,30,20],{}," loops when you want to:",[33,34,35,39,42,45],"ul",{},[36,37,38],"li",{},"print each item in a list",[36,40,41],{},"process each character in a string",[36,43,44],{},"repeat something a fixed number of times",[36,46,47],{},"go through dictionary data one piece at a time",[49,50,52],"h2",{"id":51},"quick-example","Quick example",[54,55,60],"pre",{"className":56,"code":57,"language":58,"meta":59,"style":59},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","fruits = [\"apple\", \"banana\", \"cherry\"]\n\nfor fruit in fruits:\n    print(fruit)\n","python","",[18,61,62,112,119,137],{"__ignoreMap":59},[63,64,67,71,75,79,83,87,89,92,95,98,100,102,104,107,109],"span",{"class":65,"line":66},"line",1,[63,68,70],{"class":69},"su5hD","fruits ",[63,72,74],{"class":73},"smGrS","=",[63,76,78],{"class":77},"sP7_E"," [",[63,80,82],{"class":81},"sjJ54","\"",[63,84,86],{"class":85},"s_sjI","apple",[63,88,82],{"class":81},[63,90,91],{"class":77},",",[63,93,94],{"class":81}," \"",[63,96,97],{"class":85},"banana",[63,99,82],{"class":81},[63,101,91],{"class":77},[63,103,94],{"class":81},[63,105,106],{"class":85},"cherry",[63,108,82],{"class":81},[63,110,111],{"class":77},"]\n",[63,113,115],{"class":65,"line":114},2,[63,116,118],{"emptyLinePlaceholder":117},true,"\n",[63,120,122,125,128,131,134],{"class":65,"line":121},3,[63,123,20],{"class":124},"sVHd0",[63,126,127],{"class":69}," fruit ",[63,129,130],{"class":124},"in",[63,132,133],{"class":69}," fruits",[63,135,136],{"class":77},":\n",[63,138,140,144,147,151],{"class":65,"line":139},4,[63,141,143],{"class":142},"sptTA","    print",[63,145,146],{"class":77},"(",[63,148,150],{"class":149},"slqww","fruit",[63,152,153],{"class":77},")\n",[14,155,156],{},"Output:",[54,158,160],{"className":56,"code":159,"language":58,"meta":59,"style":59},"apple\nbanana\ncherry\n",[18,161,162,167,172],{"__ignoreMap":59},[63,163,164],{"class":65,"line":66},[63,165,166],{"class":69},"apple\n",[63,168,169],{"class":65,"line":114},[63,170,171],{"class":69},"banana\n",[63,173,174],{"class":65,"line":121},[63,175,176],{"class":69},"cherry\n",[14,178,179,180,182],{},"Use a ",[18,181,20],{}," loop when you want to go through each item in a collection one by one.",[49,184,186],{"id":185},"what-a-for-loop-does","What a for loop does",[14,188,16,189,191],{},[18,190,20],{}," loop repeats a block of code once for each item in something iterable.",[14,193,194],{},"Common things you can loop over include:",[33,196,197,200,203,206,209,212],{},[36,198,199],{},"lists",[36,201,202],{},"strings",[36,204,205],{},"tuples",[36,207,208],{},"sets",[36,210,211],{},"dictionaries",[36,213,214,216],{},[18,215,24],{}," objects",[14,218,219,220,222],{},"This is useful when you know you want to process items one by one. In many beginner cases, a ",[18,221,20],{}," loop is simpler and safer than trying to track an index yourself.",[49,224,226],{"id":225},"basic-syntax","Basic syntax",[14,228,229],{},"The basic pattern looks like this:",[54,231,233],{"className":56,"code":232,"language":58,"meta":59,"style":59},"for item in collection:\n    print(item)\n",[18,234,235,249],{"__ignoreMap":59},[63,236,237,239,242,244,247],{"class":65,"line":66},[63,238,20],{"class":124},[63,240,241],{"class":69}," item ",[63,243,130],{"class":124},[63,245,246],{"class":69}," collection",[63,248,136],{"class":77},[63,250,251,253,255,258],{"class":65,"line":114},[63,252,143],{"class":142},[63,254,146],{"class":77},[63,256,257],{"class":149},"item",[63,259,153],{"class":77},[14,261,262],{},"Here is what each part means:",[33,264,265,270,275,280,286],{},[36,266,267,269],{},[18,268,20],{}," starts the loop",[36,271,272,274],{},[18,273,257],{}," is a variable name for the current value",[36,276,277,279],{},[18,278,130],{}," connects the variable to the collection",[36,281,282,285],{},[18,283,284],{},"collection"," is the thing you are looping over",[36,287,288],{},"the indented block runs once on each loop",[14,290,291],{},"Indentation matters in Python. The code inside the loop must be indented.",[14,293,294],{},"For example:",[54,296,298],{"className":56,"code":297,"language":58,"meta":59,"style":59},"for number in [1, 2, 3]:\n    print(number)\n",[18,299,300,328],{"__ignoreMap":59},[63,301,302,304,307,309,311,315,317,320,322,325],{"class":65,"line":66},[63,303,20],{"class":124},[63,305,306],{"class":69}," number ",[63,308,130],{"class":124},[63,310,78],{"class":77},[63,312,314],{"class":313},"srdBf","1",[63,316,91],{"class":77},[63,318,319],{"class":313}," 2",[63,321,91],{"class":77},[63,323,324],{"class":313}," 3",[63,326,327],{"class":77},"]:\n",[63,329,330,332,334,337],{"class":65,"line":114},[63,331,143],{"class":142},[63,333,146],{"class":77},[63,335,336],{"class":149},"number",[63,338,153],{"class":77},[14,340,156],{},[54,342,344],{"className":56,"code":343,"language":58,"meta":59,"style":59},"1\n2\n3\n",[18,345,346,351,356],{"__ignoreMap":59},[63,347,348],{"class":65,"line":66},[63,349,350],{"class":313},"1\n",[63,352,353],{"class":65,"line":114},[63,354,355],{"class":313},"2\n",[63,357,358],{"class":65,"line":121},[63,359,360],{"class":313},"3\n",[14,362,363],{},"You can read this as:",[365,366,367],"blockquote",{},[14,368,369,370,372,373,376],{},"For each ",[18,371,336],{}," in ",[18,374,375],{},"[1, 2, 3]",", print that number.",[14,378,379,380,385],{},"If indentation is confusing, see ",[381,382,384],"a",{"href":383},"\u002Flearn\u002Fpython-indentation-rules-and-why-they-matter\u002F","Python indentation rules and why they matter",".",[49,387,389],{"id":388},"looping-through-a-list","Looping through a list",[14,391,392],{},"Lists are one of the most common things to loop over.",[54,394,396],{"className":56,"code":395,"language":58,"meta":59,"style":59},"colors = [\"red\", \"green\", \"blue\"]\n\nfor color in colors:\n    print(color)\n",[18,397,398,434,438,452],{"__ignoreMap":59},[63,399,400,403,405,407,409,412,414,416,418,421,423,425,427,430,432],{"class":65,"line":66},[63,401,402],{"class":69},"colors ",[63,404,74],{"class":73},[63,406,78],{"class":77},[63,408,82],{"class":81},[63,410,411],{"class":85},"red",[63,413,82],{"class":81},[63,415,91],{"class":77},[63,417,94],{"class":81},[63,419,420],{"class":85},"green",[63,422,82],{"class":81},[63,424,91],{"class":77},[63,426,94],{"class":81},[63,428,429],{"class":85},"blue",[63,431,82],{"class":81},[63,433,111],{"class":77},[63,435,436],{"class":65,"line":114},[63,437,118],{"emptyLinePlaceholder":117},[63,439,440,442,445,447,450],{"class":65,"line":121},[63,441,20],{"class":124},[63,443,444],{"class":69}," color ",[63,446,130],{"class":124},[63,448,449],{"class":69}," colors",[63,451,136],{"class":77},[63,453,454,456,458,461],{"class":65,"line":139},[63,455,143],{"class":142},[63,457,146],{"class":77},[63,459,460],{"class":149},"color",[63,462,153],{"class":77},[14,464,156],{},[54,466,468],{"className":56,"code":467,"language":58,"meta":59,"style":59},"red\ngreen\nblue\n",[18,469,470,475,480],{"__ignoreMap":59},[63,471,472],{"class":65,"line":66},[63,473,474],{"class":69},"red\n",[63,476,477],{"class":65,"line":114},[63,478,479],{"class":69},"green\n",[63,481,482],{"class":65,"line":121},[63,483,484],{"class":69},"blue\n",[14,486,487],{},"What happens here:",[33,489,490,499,507],{},[36,491,492,493,495,496],{},"On the first loop, ",[18,494,460],{}," is ",[18,497,498],{},"\"red\"",[36,500,501,502,495,504],{},"On the second loop, ",[18,503,460],{},[18,505,506],{},"\"green\"",[36,508,509,510,495,512],{},"On the third loop, ",[18,511,460],{},[18,513,514],{},"\"blue\"",[14,516,517],{},"A good way to read this is:",[365,519,520],{},[14,521,369,522,372,524],{},[18,523,460],{},[18,525,526],{},"colors",[14,528,529],{},"That mental pattern makes loops much easier to understand.",[14,531,532,533,385],{},"If you want more list-specific examples, see ",[381,534,536],{"href":535},"\u002Fhow-to\u002Fhow-to-loop-through-a-list-in-python\u002F","how to loop through a list in Python",[49,538,540],{"id":539},"using-range-with-for-loops","Using range() with for loops",[14,542,543,544,546],{},"Use ",[18,545,24],{}," when you want to repeat something a fixed number of times.",[54,548,550],{"className":56,"code":549,"language":58,"meta":59,"style":59},"for number in range(5):\n    print(number)\n",[18,551,552,571],{"__ignoreMap":59},[63,553,554,556,558,560,563,565,568],{"class":65,"line":66},[63,555,20],{"class":124},[63,557,306],{"class":69},[63,559,130],{"class":124},[63,561,562],{"class":142}," range",[63,564,146],{"class":77},[63,566,567],{"class":313},"5",[63,569,570],{"class":77},"):\n",[63,572,573,575,577,579],{"class":65,"line":114},[63,574,143],{"class":142},[63,576,146],{"class":77},[63,578,336],{"class":149},[63,580,153],{"class":77},[14,582,156],{},[54,584,586],{"className":56,"code":585,"language":58,"meta":59,"style":59},"0\n1\n2\n3\n4\n",[18,587,588,593,597,601,605],{"__ignoreMap":59},[63,589,590],{"class":65,"line":66},[63,591,592],{"class":313},"0\n",[63,594,595],{"class":65,"line":114},[63,596,350],{"class":313},[63,598,599],{"class":65,"line":121},[63,600,355],{"class":313},[63,602,603],{"class":65,"line":139},[63,604,360],{"class":313},[63,606,608],{"class":65,"line":607},5,[63,609,610],{"class":313},"4\n",[14,612,613,616,617,620,621,385],{},[18,614,615],{},"range(5)"," gives numbers from ",[18,618,619],{},"0"," up to, but not including, ",[18,622,567],{},[14,624,625],{},"You can also use this form:",[54,627,629],{"className":56,"code":628,"language":58,"meta":59,"style":59},"for number in range(2, 10, 2):\n    print(number)\n",[18,630,631,657],{"__ignoreMap":59},[63,632,633,635,637,639,641,643,646,648,651,653,655],{"class":65,"line":66},[63,634,20],{"class":124},[63,636,306],{"class":69},[63,638,130],{"class":124},[63,640,562],{"class":142},[63,642,146],{"class":77},[63,644,645],{"class":313},"2",[63,647,91],{"class":77},[63,649,650],{"class":313}," 10",[63,652,91],{"class":77},[63,654,319],{"class":313},[63,656,570],{"class":77},[63,658,659,661,663,665],{"class":65,"line":114},[63,660,143],{"class":142},[63,662,146],{"class":77},[63,664,336],{"class":149},[63,666,153],{"class":77},[14,668,156],{},[54,670,672],{"className":56,"code":671,"language":58,"meta":59,"style":59},"2\n4\n6\n8\n",[18,673,674,678,682,687],{"__ignoreMap":59},[63,675,676],{"class":65,"line":66},[63,677,355],{"class":313},[63,679,680],{"class":65,"line":114},[63,681,610],{"class":313},[63,683,684],{"class":65,"line":121},[63,685,686],{"class":313},"6\n",[63,688,689],{"class":65,"line":139},[63,690,691],{"class":313},"8\n",[14,693,694],{},"This uses:",[33,696,697,705,713],{},[36,698,699,702,703],{},[18,700,701],{},"start",": ",[18,704,645],{},[36,706,707,702,710],{},[18,708,709],{},"stop",[18,711,712],{},"10",[36,714,715,702,718],{},[18,716,717],{},"step",[18,719,645],{},[14,721,722],{},"So the full pattern is:",[54,724,726],{"className":56,"code":725,"language":58,"meta":59,"style":59},"range(start, stop, step)\n",[18,727,728],{"__ignoreMap":59},[63,729,730,733,735,737,739,742,744,747],{"class":65,"line":66},[63,731,732],{"class":142},"range",[63,734,146],{"class":77},[63,736,701],{"class":149},[63,738,91],{"class":77},[63,740,741],{"class":149}," stop",[63,743,91],{"class":77},[63,745,746],{"class":149}," step",[63,748,153],{"class":77},[14,750,751,752,385],{},"For a full explanation, see ",[381,753,755],{"href":754},"\u002Freference\u002Fpython-range-function-explained\u002F","Python range() function explained",[49,757,759],{"id":758},"looping-through-strings-and-dictionaries","Looping through strings and dictionaries",[761,762,764],"h3",{"id":763},"looping-through-a-string","Looping through a string",[14,766,767],{},"A string loops one character at a time.",[54,769,771],{"className":56,"code":770,"language":58,"meta":59,"style":59},"word = \"cat\"\n\nfor letter in word:\n    print(letter)\n",[18,772,773,788,792,806],{"__ignoreMap":59},[63,774,775,778,780,782,785],{"class":65,"line":66},[63,776,777],{"class":69},"word ",[63,779,74],{"class":73},[63,781,94],{"class":81},[63,783,784],{"class":85},"cat",[63,786,787],{"class":81},"\"\n",[63,789,790],{"class":65,"line":114},[63,791,118],{"emptyLinePlaceholder":117},[63,793,794,796,799,801,804],{"class":65,"line":121},[63,795,20],{"class":124},[63,797,798],{"class":69}," letter ",[63,800,130],{"class":124},[63,802,803],{"class":69}," word",[63,805,136],{"class":77},[63,807,808,810,812,815],{"class":65,"line":139},[63,809,143],{"class":142},[63,811,146],{"class":77},[63,813,814],{"class":149},"letter",[63,816,153],{"class":77},[14,818,156],{},[54,820,822],{"className":56,"code":821,"language":58,"meta":59,"style":59},"c\na\nt\n",[18,823,824,829,834],{"__ignoreMap":59},[63,825,826],{"class":65,"line":66},[63,827,828],{"class":69},"c\n",[63,830,831],{"class":65,"line":114},[63,832,833],{"class":69},"a\n",[63,835,836],{"class":65,"line":121},[63,837,838],{"class":69},"t\n",[761,840,842],{"id":841},"looping-through-a-dictionary","Looping through a dictionary",[14,844,845],{},"A dictionary loops through its keys by default.",[54,847,849],{"className":56,"code":848,"language":58,"meta":59,"style":59},"person = {\n    \"name\": \"Maya\",\n    \"age\": 12\n}\n\nfor key in person:\n    print(key)\n",[18,850,851,861,884,898,903,907,922],{"__ignoreMap":59},[63,852,853,856,858],{"class":65,"line":66},[63,854,855],{"class":69},"person ",[63,857,74],{"class":73},[63,859,860],{"class":77}," {\n",[63,862,863,866,869,871,874,876,879,881],{"class":65,"line":114},[63,864,865],{"class":81},"    \"",[63,867,868],{"class":85},"name",[63,870,82],{"class":81},[63,872,873],{"class":77},":",[63,875,94],{"class":81},[63,877,878],{"class":85},"Maya",[63,880,82],{"class":81},[63,882,883],{"class":77},",\n",[63,885,886,888,891,893,895],{"class":65,"line":121},[63,887,865],{"class":81},[63,889,890],{"class":85},"age",[63,892,82],{"class":81},[63,894,873],{"class":77},[63,896,897],{"class":313}," 12\n",[63,899,900],{"class":65,"line":139},[63,901,902],{"class":77},"}\n",[63,904,905],{"class":65,"line":607},[63,906,118],{"emptyLinePlaceholder":117},[63,908,910,912,915,917,920],{"class":65,"line":909},6,[63,911,20],{"class":124},[63,913,914],{"class":69}," key ",[63,916,130],{"class":124},[63,918,919],{"class":69}," person",[63,921,136],{"class":77},[63,923,925,927,929,932],{"class":65,"line":924},7,[63,926,143],{"class":142},[63,928,146],{"class":77},[63,930,931],{"class":149},"key",[63,933,153],{"class":77},[14,935,156],{},[54,937,939],{"className":56,"code":938,"language":58,"meta":59,"style":59},"name\nage\n",[18,940,941,946],{"__ignoreMap":59},[63,942,943],{"class":65,"line":66},[63,944,945],{"class":69},"name\n",[63,947,948],{"class":65,"line":114},[63,949,950],{"class":69},"age\n",[14,952,953,954,873],{},"If you want both keys and values, you can use ",[18,955,956],{},"items()",[54,958,960],{"className":56,"code":959,"language":58,"meta":59,"style":59},"person = {\n    \"name\": \"Maya\",\n    \"age\": 12\n}\n\nfor key, value in person.items():\n    print(key, value)\n",[18,961,962,970,988,1000,1004,1008,1032],{"__ignoreMap":59},[63,963,964,966,968],{"class":65,"line":66},[63,965,855],{"class":69},[63,967,74],{"class":73},[63,969,860],{"class":77},[63,971,972,974,976,978,980,982,984,986],{"class":65,"line":114},[63,973,865],{"class":81},[63,975,868],{"class":85},[63,977,82],{"class":81},[63,979,873],{"class":77},[63,981,94],{"class":81},[63,983,878],{"class":85},[63,985,82],{"class":81},[63,987,883],{"class":77},[63,989,990,992,994,996,998],{"class":65,"line":121},[63,991,865],{"class":81},[63,993,890],{"class":85},[63,995,82],{"class":81},[63,997,873],{"class":77},[63,999,897],{"class":313},[63,1001,1002],{"class":65,"line":139},[63,1003,902],{"class":77},[63,1005,1006],{"class":65,"line":607},[63,1007,118],{"emptyLinePlaceholder":117},[63,1009,1010,1012,1015,1017,1020,1022,1024,1026,1029],{"class":65,"line":909},[63,1011,20],{"class":124},[63,1013,1014],{"class":69}," key",[63,1016,91],{"class":77},[63,1018,1019],{"class":69}," value ",[63,1021,130],{"class":124},[63,1023,919],{"class":69},[63,1025,385],{"class":77},[63,1027,1028],{"class":149},"items",[63,1030,1031],{"class":77},"():\n",[63,1033,1034,1036,1038,1040,1042,1045],{"class":65,"line":924},[63,1035,143],{"class":142},[63,1037,146],{"class":77},[63,1039,931],{"class":149},[63,1041,91],{"class":77},[63,1043,1044],{"class":149}," value",[63,1046,153],{"class":77},[14,1048,156],{},[54,1050,1052],{"className":56,"code":1051,"language":58,"meta":59,"style":59},"name Maya\nage 12\n",[18,1053,1054,1059],{"__ignoreMap":59},[63,1055,1056],{"class":65,"line":66},[63,1057,1058],{"class":69},"name Maya\n",[63,1060,1061,1064],{"class":65,"line":114},[63,1062,1063],{"class":69},"age ",[63,1065,1066],{"class":313},"12\n",[14,1068,1069],{},"Keep it simple at first:",[33,1071,1072,1075],{},[36,1073,1074],{},"looping over a string gives characters",[36,1076,1077],{},"looping over a dictionary gives keys by default",[49,1079,1081],{"id":1080},"using-break-and-continue","Using break and continue",[761,1083,1084],{"id":1084},"break",[14,1086,1087,1089],{},[18,1088,1084],{}," stops the loop early.",[54,1091,1093],{"className":56,"code":1092,"language":58,"meta":59,"style":59},"for number in range(10):\n    if number == 4:\n        break\n    print(number)\n",[18,1094,1095,1111,1126,1131],{"__ignoreMap":59},[63,1096,1097,1099,1101,1103,1105,1107,1109],{"class":65,"line":66},[63,1098,20],{"class":124},[63,1100,306],{"class":69},[63,1102,130],{"class":124},[63,1104,562],{"class":142},[63,1106,146],{"class":77},[63,1108,712],{"class":313},[63,1110,570],{"class":77},[63,1112,1113,1116,1118,1121,1124],{"class":65,"line":114},[63,1114,1115],{"class":124},"    if",[63,1117,306],{"class":69},[63,1119,1120],{"class":73},"==",[63,1122,1123],{"class":313}," 4",[63,1125,136],{"class":77},[63,1127,1128],{"class":65,"line":121},[63,1129,1130],{"class":124},"        break\n",[63,1132,1133,1135,1137,1139],{"class":65,"line":139},[63,1134,143],{"class":142},[63,1136,146],{"class":77},[63,1138,336],{"class":149},[63,1140,153],{"class":77},[14,1142,156],{},[54,1144,1146],{"className":56,"code":1145,"language":58,"meta":59,"style":59},"0\n1\n2\n3\n",[18,1147,1148,1152,1156,1160],{"__ignoreMap":59},[63,1149,1150],{"class":65,"line":66},[63,1151,592],{"class":313},[63,1153,1154],{"class":65,"line":114},[63,1155,350],{"class":313},[63,1157,1158],{"class":65,"line":121},[63,1159,355],{"class":313},[63,1161,1162],{"class":65,"line":139},[63,1163,360],{"class":313},[14,1165,1166,1167,1169,1170,1173],{},"As soon as ",[18,1168,336],{}," becomes ",[18,1171,1172],{},"4",", the loop ends.",[761,1175,1176],{"id":1176},"continue",[14,1178,1179,1181],{},[18,1180,1176],{}," skips the current loop and moves to the next one.",[54,1183,1185],{"className":56,"code":1184,"language":58,"meta":59,"style":59},"for number in range(5):\n    if number == 2:\n        continue\n    print(number)\n",[18,1186,1187,1203,1215,1220],{"__ignoreMap":59},[63,1188,1189,1191,1193,1195,1197,1199,1201],{"class":65,"line":66},[63,1190,20],{"class":124},[63,1192,306],{"class":69},[63,1194,130],{"class":124},[63,1196,562],{"class":142},[63,1198,146],{"class":77},[63,1200,567],{"class":313},[63,1202,570],{"class":77},[63,1204,1205,1207,1209,1211,1213],{"class":65,"line":114},[63,1206,1115],{"class":124},[63,1208,306],{"class":69},[63,1210,1120],{"class":73},[63,1212,319],{"class":313},[63,1214,136],{"class":77},[63,1216,1217],{"class":65,"line":121},[63,1218,1219],{"class":124},"        continue\n",[63,1221,1222,1224,1226,1228],{"class":65,"line":139},[63,1223,143],{"class":142},[63,1225,146],{"class":77},[63,1227,336],{"class":149},[63,1229,153],{"class":77},[14,1231,156],{},[54,1233,1235],{"className":56,"code":1234,"language":58,"meta":59,"style":59},"0\n1\n3\n4\n",[18,1236,1237,1241,1245,1249],{"__ignoreMap":59},[63,1238,1239],{"class":65,"line":66},[63,1240,592],{"class":313},[63,1242,1243],{"class":65,"line":114},[63,1244,350],{"class":313},[63,1246,1247],{"class":65,"line":121},[63,1248,360],{"class":313},[63,1250,1251],{"class":65,"line":139},[63,1252,610],{"class":313},[14,1254,1255,1256,495,1258,1260,1261,1264],{},"When ",[18,1257,336],{},[18,1259,645],{},", ",[18,1262,1263],{},"print(number)"," is skipped.",[14,1266,1267,1268,385],{},"For a full guide, see ",[381,1269,1271],{"href":1270},"\u002Flearn\u002Fpython-break-and-continue-statements\u002F","Python break and continue statements",[49,1273,1275],{"id":1274},"using-else-with-a-for-loop","Using else with a for loop",[14,1277,16,1278,1280,1281,1284],{},[18,1279,20],{}," loop can have an ",[18,1282,1283],{},"else"," block.",[14,1286,1287,1288,1290],{},"The ",[18,1289,1283],{}," runs if the loop finishes normally.",[54,1292,1294],{"className":56,"code":1293,"language":58,"meta":59,"style":59},"for number in range(3):\n    print(number)\nelse:\n    print(\"Loop finished\")\n",[18,1295,1296,1313,1323,1329],{"__ignoreMap":59},[63,1297,1298,1300,1302,1304,1306,1308,1311],{"class":65,"line":66},[63,1299,20],{"class":124},[63,1301,306],{"class":69},[63,1303,130],{"class":124},[63,1305,562],{"class":142},[63,1307,146],{"class":77},[63,1309,1310],{"class":313},"3",[63,1312,570],{"class":77},[63,1314,1315,1317,1319,1321],{"class":65,"line":114},[63,1316,143],{"class":142},[63,1318,146],{"class":77},[63,1320,336],{"class":149},[63,1322,153],{"class":77},[63,1324,1325,1327],{"class":65,"line":121},[63,1326,1283],{"class":124},[63,1328,136],{"class":77},[63,1330,1331,1333,1335,1337,1340,1342],{"class":65,"line":139},[63,1332,143],{"class":142},[63,1334,146],{"class":77},[63,1336,82],{"class":81},[63,1338,1339],{"class":85},"Loop finished",[63,1341,82],{"class":81},[63,1343,153],{"class":77},[14,1345,156],{},[54,1347,1349],{"className":56,"code":1348,"language":58,"meta":59,"style":59},"0\n1\n2\nLoop finished\n",[18,1350,1351,1355,1359,1363],{"__ignoreMap":59},[63,1352,1353],{"class":65,"line":66},[63,1354,592],{"class":313},[63,1356,1357],{"class":65,"line":114},[63,1358,350],{"class":313},[63,1360,1361],{"class":65,"line":121},[63,1362,355],{"class":313},[63,1364,1365],{"class":65,"line":139},[63,1366,1367],{"class":69},"Loop finished\n",[14,1369,1370,1371,1373,1374,1376],{},"But if ",[18,1372,1084],{}," happens, the ",[18,1375,1283],{}," block does not run.",[54,1378,1380],{"className":56,"code":1379,"language":58,"meta":59,"style":59},"for number in range(3):\n    if number == 1:\n        break\n    print(number)\nelse:\n    print(\"Loop finished\")\n",[18,1381,1382,1398,1411,1415,1425,1431],{"__ignoreMap":59},[63,1383,1384,1386,1388,1390,1392,1394,1396],{"class":65,"line":66},[63,1385,20],{"class":124},[63,1387,306],{"class":69},[63,1389,130],{"class":124},[63,1391,562],{"class":142},[63,1393,146],{"class":77},[63,1395,1310],{"class":313},[63,1397,570],{"class":77},[63,1399,1400,1402,1404,1406,1409],{"class":65,"line":114},[63,1401,1115],{"class":124},[63,1403,306],{"class":69},[63,1405,1120],{"class":73},[63,1407,1408],{"class":313}," 1",[63,1410,136],{"class":77},[63,1412,1413],{"class":65,"line":121},[63,1414,1130],{"class":124},[63,1416,1417,1419,1421,1423],{"class":65,"line":139},[63,1418,143],{"class":142},[63,1420,146],{"class":77},[63,1422,336],{"class":149},[63,1424,153],{"class":77},[63,1426,1427,1429],{"class":65,"line":607},[63,1428,1283],{"class":124},[63,1430,136],{"class":77},[63,1432,1433,1435,1437,1439,1441,1443],{"class":65,"line":909},[63,1434,143],{"class":142},[63,1436,146],{"class":77},[63,1438,82],{"class":81},[63,1440,1339],{"class":85},[63,1442,82],{"class":81},[63,1444,153],{"class":77},[14,1446,156],{},[54,1448,1449],{"className":56,"code":592,"language":58,"meta":59,"style":59},[18,1450,1451],{"__ignoreMap":59},[63,1452,1453],{"class":65,"line":66},[63,1454,592],{"class":313},[14,1456,1457],{},"This feature is real and useful sometimes, but many beginners do not need it right away.",[49,1459,1461],{"id":1460},"common-beginner-mistakes","Common beginner mistakes",[14,1463,1464,1465,1467],{},"Here are some common problems with ",[18,1466,20],{}," loops.",[761,1469,1471],{"id":1470},"forgetting-the-colon","Forgetting the colon",[14,1473,1474,1475,385],{},"This causes a ",[18,1476,1477],{},"SyntaxError",[14,1479,1480],{},"Wrong:",[54,1482,1484],{"className":56,"code":1483,"language":58,"meta":59,"style":59},"for item in [1, 2, 3]\n    print(item)\n",[18,1485,1486,1508],{"__ignoreMap":59},[63,1487,1488,1490,1492,1494,1496,1498,1500,1502,1504,1506],{"class":65,"line":66},[63,1489,20],{"class":124},[63,1491,241],{"class":69},[63,1493,130],{"class":124},[63,1495,78],{"class":77},[63,1497,314],{"class":313},[63,1499,91],{"class":77},[63,1501,319],{"class":313},[63,1503,91],{"class":77},[63,1505,324],{"class":313},[63,1507,111],{"class":77},[63,1509,1510,1512,1514,1516],{"class":65,"line":114},[63,1511,143],{"class":142},[63,1513,146],{"class":77},[63,1515,257],{"class":149},[63,1517,153],{"class":77},[14,1519,1520],{},"Correct:",[54,1522,1524],{"className":56,"code":1523,"language":58,"meta":59,"style":59},"for item in [1, 2, 3]:\n    print(item)\n",[18,1525,1526,1548],{"__ignoreMap":59},[63,1527,1528,1530,1532,1534,1536,1538,1540,1542,1544,1546],{"class":65,"line":66},[63,1529,20],{"class":124},[63,1531,241],{"class":69},[63,1533,130],{"class":124},[63,1535,78],{"class":77},[63,1537,314],{"class":313},[63,1539,91],{"class":77},[63,1541,319],{"class":313},[63,1543,91],{"class":77},[63,1545,324],{"class":313},[63,1547,327],{"class":77},[63,1549,1550,1552,1554,1556],{"class":65,"line":114},[63,1551,143],{"class":142},[63,1553,146],{"class":77},[63,1555,257],{"class":149},[63,1557,153],{"class":77},[761,1559,1561],{"id":1560},"using-bad-indentation","Using bad indentation",[14,1563,1564],{},"The code inside the loop must be indented.",[14,1566,1480],{},[54,1568,1570],{"className":56,"code":1569,"language":58,"meta":59,"style":59},"for item in [1, 2, 3]:\nprint(item)\n",[18,1571,1572,1594],{"__ignoreMap":59},[63,1573,1574,1576,1578,1580,1582,1584,1586,1588,1590,1592],{"class":65,"line":66},[63,1575,20],{"class":124},[63,1577,241],{"class":69},[63,1579,130],{"class":124},[63,1581,78],{"class":77},[63,1583,314],{"class":313},[63,1585,91],{"class":77},[63,1587,319],{"class":313},[63,1589,91],{"class":77},[63,1591,324],{"class":313},[63,1593,327],{"class":77},[63,1595,1596,1599,1601,1603],{"class":65,"line":114},[63,1597,1598],{"class":142},"print",[63,1600,146],{"class":77},[63,1602,257],{"class":149},[63,1604,153],{"class":77},[14,1606,1520],{},[54,1608,1609],{"className":56,"code":1523,"language":58,"meta":59,"style":59},[18,1610,1611,1633],{"__ignoreMap":59},[63,1612,1613,1615,1617,1619,1621,1623,1625,1627,1629,1631],{"class":65,"line":66},[63,1614,20],{"class":124},[63,1616,241],{"class":69},[63,1618,130],{"class":124},[63,1620,78],{"class":77},[63,1622,314],{"class":313},[63,1624,91],{"class":77},[63,1626,319],{"class":313},[63,1628,91],{"class":77},[63,1630,324],{"class":313},[63,1632,327],{"class":77},[63,1634,1635,1637,1639,1641],{"class":65,"line":114},[63,1636,143],{"class":142},[63,1638,146],{"class":77},[63,1640,257],{"class":149},[63,1642,153],{"class":77},[14,1644,1645,1646,385],{},"If you get this error, see ",[381,1647,1649],{"href":1648},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix\u002F","IndentationError: expected an indented block",[761,1651,1653,1654,1656],{"id":1652},"expecting-range5-to-include-5","Expecting ",[18,1655,615],{}," to include 5",[14,1658,1659,1660,385],{},"It does not include ",[18,1661,567],{},[54,1663,1664],{"className":56,"code":549,"language":58,"meta":59,"style":59},[18,1665,1666,1682],{"__ignoreMap":59},[63,1667,1668,1670,1672,1674,1676,1678,1680],{"class":65,"line":66},[63,1669,20],{"class":124},[63,1671,306],{"class":69},[63,1673,130],{"class":124},[63,1675,562],{"class":142},[63,1677,146],{"class":77},[63,1679,567],{"class":313},[63,1681,570],{"class":77},[63,1683,1684,1686,1688,1690],{"class":65,"line":114},[63,1685,143],{"class":142},[63,1687,146],{"class":77},[63,1689,336],{"class":149},[63,1691,153],{"class":77},[14,1693,156],{},[54,1695,1696],{"className":56,"code":585,"language":58,"meta":59,"style":59},[18,1697,1698,1702,1706,1710,1714],{"__ignoreMap":59},[63,1699,1700],{"class":65,"line":66},[63,1701,592],{"class":313},[63,1703,1704],{"class":65,"line":114},[63,1705,350],{"class":313},[63,1707,1708],{"class":65,"line":121},[63,1709,355],{"class":313},[63,1711,1712],{"class":65,"line":139},[63,1713,360],{"class":313},[63,1715,1716],{"class":65,"line":607},[63,1717,610],{"class":313},[761,1719,1721],{"id":1720},"changing-the-loop-variable-and-expecting-the-original-collection-to-change","Changing the loop variable and expecting the original collection to change",[14,1723,1724],{},"This does not change the original list:",[54,1726,1728],{"className":56,"code":1727,"language":58,"meta":59,"style":59},"numbers = [1, 2, 3]\n\nfor number in numbers:\n    number = 99\n\nprint(numbers)\n",[18,1729,1730,1751,1755,1768,1778,1782],{"__ignoreMap":59},[63,1731,1732,1735,1737,1739,1741,1743,1745,1747,1749],{"class":65,"line":66},[63,1733,1734],{"class":69},"numbers ",[63,1736,74],{"class":73},[63,1738,78],{"class":77},[63,1740,314],{"class":313},[63,1742,91],{"class":77},[63,1744,319],{"class":313},[63,1746,91],{"class":77},[63,1748,324],{"class":313},[63,1750,111],{"class":77},[63,1752,1753],{"class":65,"line":114},[63,1754,118],{"emptyLinePlaceholder":117},[63,1756,1757,1759,1761,1763,1766],{"class":65,"line":121},[63,1758,20],{"class":124},[63,1760,306],{"class":69},[63,1762,130],{"class":124},[63,1764,1765],{"class":69}," numbers",[63,1767,136],{"class":77},[63,1769,1770,1773,1775],{"class":65,"line":139},[63,1771,1772],{"class":69},"    number ",[63,1774,74],{"class":73},[63,1776,1777],{"class":313}," 99\n",[63,1779,1780],{"class":65,"line":607},[63,1781,118],{"emptyLinePlaceholder":117},[63,1783,1784,1786,1788,1791],{"class":65,"line":909},[63,1785,1598],{"class":142},[63,1787,146],{"class":77},[63,1789,1790],{"class":149},"numbers",[63,1792,153],{"class":77},[14,1794,156],{},[54,1796,1798],{"className":56,"code":1797,"language":58,"meta":59,"style":59},"[1, 2, 3]\n",[18,1799,1800],{"__ignoreMap":59},[63,1801,1802,1805,1807,1809,1811,1813,1815],{"class":65,"line":66},[63,1803,1804],{"class":77},"[",[63,1806,314],{"class":313},[63,1808,91],{"class":77},[63,1810,319],{"class":313},[63,1812,91],{"class":77},[63,1814,324],{"class":313},[63,1816,111],{"class":77},[14,1818,1819,1820,1822],{},"The loop variable ",[18,1821,336],{}," is just a temporary name for each value.",[761,1824,1826],{"id":1825},"confusing-values-with-indexes","Confusing values with indexes",[14,1828,1829],{},"This loop gives values, not index positions:",[54,1831,1833],{"className":56,"code":1832,"language":58,"meta":59,"style":59},"animals = [\"cat\", \"dog\", \"bird\"]\n\nfor animal in animals:\n    print(animal)\n",[18,1834,1835,1870,1874,1888],{"__ignoreMap":59},[63,1836,1837,1840,1842,1844,1846,1848,1850,1852,1854,1857,1859,1861,1863,1866,1868],{"class":65,"line":66},[63,1838,1839],{"class":69},"animals ",[63,1841,74],{"class":73},[63,1843,78],{"class":77},[63,1845,82],{"class":81},[63,1847,784],{"class":85},[63,1849,82],{"class":81},[63,1851,91],{"class":77},[63,1853,94],{"class":81},[63,1855,1856],{"class":85},"dog",[63,1858,82],{"class":81},[63,1860,91],{"class":77},[63,1862,94],{"class":81},[63,1864,1865],{"class":85},"bird",[63,1867,82],{"class":81},[63,1869,111],{"class":77},[63,1871,1872],{"class":65,"line":114},[63,1873,118],{"emptyLinePlaceholder":117},[63,1875,1876,1878,1881,1883,1886],{"class":65,"line":121},[63,1877,20],{"class":124},[63,1879,1880],{"class":69}," animal ",[63,1882,130],{"class":124},[63,1884,1885],{"class":69}," animals",[63,1887,136],{"class":77},[63,1889,1890,1892,1894,1897],{"class":65,"line":139},[63,1891,143],{"class":142},[63,1893,146],{"class":77},[63,1895,1896],{"class":149},"animal",[63,1898,153],{"class":77},[14,1900,1901,1902,1905,1906,385],{},"If you need both the index and the value, use ",[18,1903,1904],{},"enumerate()",". See ",[381,1907,1909],{"href":1908},"\u002Fhow-to\u002Fhow-to-use-enumerate-in-python\u002F","how to use enumerate in Python",[49,1911,1913],{"id":1912},"when-to-use-a-for-loop-vs-while-loop","When to use a for loop vs while loop",[14,1915,179,1916,1918],{},[18,1917,20],{}," loop when:",[33,1920,1921,1924,1927],{},[36,1922,1923],{},"you are looping over items",[36,1925,1926],{},"you are looping over a known range",[36,1928,1929],{},"you know how many times something should happen",[14,1931,179,1932,1918],{},[18,1933,1934],{},"while",[33,1936,1937,1940],{},[36,1938,1939],{},"you want to keep going until a condition becomes false",[36,1941,1942],{},"you do not know in advance how many times the loop will run",[14,1944,1945],{},"Example idea:",[33,1947,1948,1953],{},[36,1949,1950,1952],{},[18,1951,20],{},": go through every item in a list",[36,1954,1955,1957,1958],{},[18,1956,1934],{},": keep asking for input until the user enters ",[18,1959,1960],{},"\"quit\"",[14,1962,1963,1964,385],{},"For a full comparison, see ",[381,1965,1967],{"href":1966},"\u002Flearn\u002Fpython-while-loops-explained\u002F","Python while loops explained",[49,1969,1971],{"id":1970},"debugging-for-loop-problems","Debugging for loop problems",[14,1973,1974],{},"If your loop is not working as expected, these quick checks can help.",[761,1976,1978],{"id":1977},"check-the-current-value","Check the current value",[54,1980,1982],{"className":56,"code":1981,"language":58,"meta":59,"style":59},"print(item)\n",[18,1983,1984],{"__ignoreMap":59},[63,1985,1986,1988,1990,1992],{"class":65,"line":66},[63,1987,1598],{"class":142},[63,1989,146],{"class":77},[63,1991,257],{"class":149},[63,1993,153],{"class":77},[14,1995,1996],{},"This helps you see what the loop variable contains on each iteration.",[761,1998,2000],{"id":1999},"check-the-type-of-the-thing-you-are-looping-over","Check the type of the thing you are looping over",[54,2002,2004],{"className":56,"code":2003,"language":58,"meta":59,"style":59},"print(type(collection))\n",[18,2005,2006],{"__ignoreMap":59},[63,2007,2008,2010,2012,2016,2018,2020],{"class":65,"line":66},[63,2009,1598],{"class":142},[63,2011,146],{"class":77},[63,2013,2015],{"class":2014},"sZMiF","type",[63,2017,146],{"class":77},[63,2019,284],{"class":149},[63,2021,2022],{"class":77},"))\n",[14,2024,2025],{},"This is useful if you are not sure whether your variable is a list, string, dictionary, or something else.",[761,2027,2029,2030,2032],{"id":2028},"see-what-range5-really-contains","See what ",[18,2031,615],{}," really contains",[54,2034,2036],{"className":56,"code":2035,"language":58,"meta":59,"style":59},"print(list(range(5)))\n",[18,2037,2038],{"__ignoreMap":59},[63,2039,2040,2042,2044,2047,2049,2051,2053,2055],{"class":65,"line":66},[63,2041,1598],{"class":142},[63,2043,146],{"class":77},[63,2045,2046],{"class":2014},"list",[63,2048,146],{"class":77},[63,2050,732],{"class":142},[63,2052,146],{"class":77},[63,2054,567],{"class":313},[63,2056,2057],{"class":77},")))\n",[14,2059,156],{},[54,2061,2063],{"className":56,"code":2062,"language":58,"meta":59,"style":59},"[0, 1, 2, 3, 4]\n",[18,2064,2065],{"__ignoreMap":59},[63,2066,2067,2069,2071,2073,2075,2077,2079,2081,2083,2085,2087],{"class":65,"line":66},[63,2068,1804],{"class":77},[63,2070,619],{"class":313},[63,2072,91],{"class":77},[63,2074,1408],{"class":313},[63,2076,91],{"class":77},[63,2078,319],{"class":313},[63,2080,91],{"class":77},[63,2082,324],{"class":313},[63,2084,91],{"class":77},[63,2086,1123],{"class":313},[63,2088,111],{"class":77},[761,2090,2092],{"id":2091},"check-dictionary-keys","Check dictionary keys",[54,2094,2096],{"className":56,"code":2095,"language":58,"meta":59,"style":59},"print(my_dict.keys())\n",[18,2097,2098],{"__ignoreMap":59},[63,2099,2100,2102,2104,2107,2109,2112],{"class":65,"line":66},[63,2101,1598],{"class":142},[63,2103,146],{"class":77},[63,2105,2106],{"class":149},"my_dict",[63,2108,385],{"class":77},[63,2110,2111],{"class":149},"keys",[63,2113,2114],{"class":77},"())\n",[14,2116,2117],{},"This shows the keys in a dictionary.",[761,2119,2121],{"id":2120},"read-help-for-range","Read help for range()",[54,2123,2125],{"className":56,"code":2124,"language":58,"meta":59,"style":59},"help(range)\n",[18,2126,2127],{"__ignoreMap":59},[63,2128,2129,2132,2134,2136],{"class":65,"line":66},[63,2130,2131],{"class":142},"help",[63,2133,146],{"class":77},[63,2135,732],{"class":142},[63,2137,153],{"class":77},[14,2139,2140,2141,2143],{},"This can show how ",[18,2142,24],{}," works directly in Python.",[14,2145,2146],{},"Common errors related to loops include:",[33,2148,2149,2156,2162,2168],{},[36,2150,2151,2153,2154],{},[18,2152,1477],{}," from a missing colon after ",[18,2155,20],{},[36,2157,2158,2161],{},[18,2159,2160],{},"IndentationError"," from missing or inconsistent indentation",[36,2163,2164,2167],{},[18,2165,2166],{},"TypeError"," when trying to loop over a non-iterable value like an integer",[36,2169,2170,2173],{},[18,2171,2172],{},"NameError"," from using a variable that was never defined",[14,2175,2176,2177,385],{},"If you see a non-iterable error, see ",[381,2178,2180],{"href":2179},"\u002Ferrors\u002Ftypeerror-int-object-is-not-iterable-fix\u002F","TypeError: int object is not iterable",[49,2182,2184],{"id":2183},"faq","FAQ",[761,2186,2188],{"id":2187},"what-does-a-for-loop-do-in-python","What does a for loop do in Python?",[14,2190,2191,2192,385],{},"It runs a block of code once for each item in an iterable such as a list, string, or ",[18,2193,732],{},[761,2195,2197],{"id":2196},"what-can-i-loop-over-in-python","What can I loop over in Python?",[14,2199,2200,2201,2203],{},"You can loop over lists, tuples, strings, sets, dictionaries, and ",[18,2202,24],{}," objects.",[761,2205,2207],{"id":2206},"does-range5-include-5","Does range(5) include 5?",[14,2209,2210,2211,1260,2213,1260,2215,1260,2217,2219,2220,385],{},"No. It gives ",[18,2212,619],{},[18,2214,314],{},[18,2216,645],{},[18,2218,1310],{},", and ",[18,2221,1172],{},[761,2223,2225],{"id":2224},"what-is-the-difference-between-for-and-while-in-python","What is the difference between for and while in Python?",[14,2227,16,2228,2230,2231,2233],{},[18,2229,20],{}," loop is usually for going through items. A ",[18,2232,1934],{}," loop repeats while a condition is true.",[761,2235,2237],{"id":2236},"how-do-i-stop-a-for-loop-early","How do I stop a for loop early?",[14,2239,543,2240,2242],{},[18,2241,1084],{}," to exit the loop before it finishes.",[49,2244,2246],{"id":2245},"see-also","See also",[33,2248,2249,2253,2257,2261,2266,2271],{},[36,2250,2251],{},[381,2252,1967],{"href":1966},[36,2254,2255],{},[381,2256,1271],{"href":1270},[36,2258,2259],{},[381,2260,755],{"href":754},[36,2262,2263],{},[381,2264,2265],{"href":535},"How to loop through a list in Python",[36,2267,2268],{},[381,2269,2270],{"href":1908},"How to use enumerate in Python",[36,2272,2273],{},[381,2274,384],{"href":383},[14,2276,2277,2278,2281,2282,2284],{},"Once you understand the basic ",[18,2279,2280],{},"for item in collection:"," pattern, you can use loops for many real Python tasks like printing values, counting with ",[18,2283,24],{},", and processing data one item at a time.",[2286,2287,2288],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":59,"searchDepth":114,"depth":114,"links":2290},[2291,2292,2293,2294,2295,2296,2300,2304,2305,2313,2314,2322,2329],{"id":51,"depth":114,"text":52},{"id":185,"depth":114,"text":186},{"id":225,"depth":114,"text":226},{"id":388,"depth":114,"text":389},{"id":539,"depth":114,"text":540},{"id":758,"depth":114,"text":759,"children":2297},[2298,2299],{"id":763,"depth":121,"text":764},{"id":841,"depth":121,"text":842},{"id":1080,"depth":114,"text":1081,"children":2301},[2302,2303],{"id":1084,"depth":121,"text":1084},{"id":1176,"depth":121,"text":1176},{"id":1274,"depth":114,"text":1275},{"id":1460,"depth":114,"text":1461,"children":2306},[2307,2308,2309,2311,2312],{"id":1470,"depth":121,"text":1471},{"id":1560,"depth":121,"text":1561},{"id":1652,"depth":121,"text":2310},"Expecting range(5) to include 5",{"id":1720,"depth":121,"text":1721},{"id":1825,"depth":121,"text":1826},{"id":1912,"depth":114,"text":1913},{"id":1970,"depth":114,"text":1971,"children":2315},[2316,2317,2318,2320,2321],{"id":1977,"depth":121,"text":1978},{"id":1999,"depth":121,"text":2000},{"id":2028,"depth":121,"text":2319},"See what range(5) really contains",{"id":2091,"depth":121,"text":2092},{"id":2120,"depth":121,"text":2121},{"id":2183,"depth":114,"text":2184,"children":2323},[2324,2325,2326,2327,2328],{"id":2187,"depth":121,"text":2188},{"id":2196,"depth":121,"text":2197},{"id":2206,"depth":121,"text":2207},{"id":2224,"depth":121,"text":2225},{"id":2236,"depth":121,"text":2237},{"id":2245,"depth":114,"text":2246},"Master python for loops explained in our comprehensive Python beginner guide.","md",{},"\u002Flearn\u002Fpython-for-loops-explained",{"title":5,"description":2330},"learn\u002Fpython-for-loops-explained","HEIiab2Yq8XSoRMek96eYs94xipHXnu3M07viULNZbU",1777585494798]