[{"data":1,"prerenderedAt":1386},["ShallowReactive",2],{"doc-\u002Ferrors\u002Ftypeerror-int-object-is-not-iterable-fix":3},{"id":4,"title":5,"body":6,"description":1379,"extension":1380,"meta":1381,"navigation":63,"path":1382,"seo":1383,"stem":1384,"__hash__":1385},"content\u002Ferrors\u002Ftypeerror-int-object-is-not-iterable-fix.md","TypeError: 'int' object is not iterable (Fix)",{"type":7,"value":8,"toc":1358},"minimark",[9,19,27,32,151,162,166,169,177,180,214,220,224,227,249,253,256,284,287,323,326,336,343,346,357,390,393,423,432,445,449,452,455,499,502,559,561,578,581,626,628,656,665,669,672,675,721,723,739,750,757,761,764,767,862,865,935,938,962,965,983,987,990,1012,1015,1050,1053,1057,1060,1099,1102,1178,1185,1189,1194,1199,1209,1217,1221,1228,1232,1235,1266,1269,1296,1300,1348,1354],[10,11,13,14,18],"h1",{"id":12},"typeerror-int-object-is-not-iterable-fix","TypeError: ",[15,16,17],"code",{},"'int' object is not iterable"," (Fix)",[20,21,22,23,26],"p",{},"Fix the Python error ",[15,24,25],{},"TypeError: 'int' object is not iterable",". This page explains what the error means, why it happens, and the most common ways to correct your code.",[28,29,31],"h2",{"id":30},"quick-fix","Quick fix",[33,34,39],"pre",{"className":35,"code":36,"language":37,"meta":38,"style":38},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","number = 5\n\n# Wrong\nfor item in number:\n    print(item)\n\n# Right: loop over a range\nfor item in range(number):\n    print(item)\n","python","",[15,40,41,58,65,72,92,109,114,120,140],{"__ignoreMap":38},[42,43,46,50,54],"span",{"class":44,"line":45},"line",1,[42,47,49],{"class":48},"su5hD","number ",[42,51,53],{"class":52},"smGrS","=",[42,55,57],{"class":56},"srdBf"," 5\n",[42,59,61],{"class":44,"line":60},2,[42,62,64],{"emptyLinePlaceholder":63},true,"\n",[42,66,68],{"class":44,"line":67},3,[42,69,71],{"class":70},"sutJx","# Wrong\n",[42,73,75,79,82,85,88],{"class":44,"line":74},4,[42,76,78],{"class":77},"sVHd0","for",[42,80,81],{"class":48}," item ",[42,83,84],{"class":77},"in",[42,86,87],{"class":48}," number",[42,89,91],{"class":90},"sP7_E",":\n",[42,93,95,99,102,106],{"class":44,"line":94},5,[42,96,98],{"class":97},"sptTA","    print",[42,100,101],{"class":90},"(",[42,103,105],{"class":104},"slqww","item",[42,107,108],{"class":90},")\n",[42,110,112],{"class":44,"line":111},6,[42,113,64],{"emptyLinePlaceholder":63},[42,115,117],{"class":44,"line":116},7,[42,118,119],{"class":70},"# Right: loop over a range\n",[42,121,123,125,127,129,132,134,137],{"class":44,"line":122},8,[42,124,78],{"class":77},[42,126,81],{"class":48},[42,128,84],{"class":77},[42,130,131],{"class":97}," range",[42,133,101],{"class":90},[42,135,136],{"class":104},"number",[42,138,139],{"class":90},"):\n",[42,141,143,145,147,149],{"class":44,"line":142},9,[42,144,98],{"class":97},[42,146,101],{"class":90},[42,148,105],{"class":104},[42,150,108],{"class":90},[20,152,153,154,161],{},"An integer is a single number, not a collection. If you want to loop a certain number of times, use ",[155,156,158],"a",{"href":157},"\u002Freference\u002Fpython-range-function-explained\u002F",[15,159,160],{},"range()",". If you meant to loop over values, make sure the variable is a list, tuple, string, or another iterable.",[28,163,165],{"id":164},"what-this-error-means","What this error means",[20,167,168],{},"Python raises this error when your code tries to use an integer in a place where an iterable is required.",[20,170,171,172,176],{},"An ",[173,174,175],"strong",{},"iterable"," is an object you can loop over one item at a time.",[20,178,179],{},"Common iterables include:",[181,182,183,189,194,199,204,209],"ul",{},[184,185,186],"li",{},[15,187,188],{},"list",[184,190,191],{},[15,192,193],{},"tuple",[184,195,196],{},[15,197,198],{},"string",[184,200,201],{},[15,202,203],{},"dictionary",[184,205,206],{},[15,207,208],{},"set",[184,210,211],{},[15,212,213],{},"range",[20,215,171,216,219],{},[15,217,218],{},"int"," is different. It is just one value, so Python cannot iterate over it.",[28,221,223],{"id":222},"when-this-error-usually-happens","When this error usually happens",[20,225,226],{},"This error often appears in situations like these:",[181,228,229,235,243,246],{},[184,230,231,232],{},"Using ",[15,233,234],{},"for item in my_number",[184,236,231,237,239,240],{},[15,238,84],{}," with a number, such as ",[15,241,242],{},"'a' in 5",[184,244,245],{},"Passing an integer to a function that expects an iterable",[184,247,248],{},"Accidentally replacing a list variable with an integer",[28,250,252],{"id":251},"example-that-causes-the-error","Example that causes the error",[20,254,255],{},"Here is a simple example:",[33,257,259],{"className":35,"code":258,"language":37,"meta":38,"style":38},"for item in 10:\n    print(item)\n",[15,260,261,274],{"__ignoreMap":38},[42,262,263,265,267,269,272],{"class":44,"line":45},[42,264,78],{"class":77},[42,266,81],{"class":48},[42,268,84],{"class":77},[42,270,271],{"class":56}," 10",[42,273,91],{"class":90},[42,275,276,278,280,282],{"class":44,"line":60},[42,277,98],{"class":97},[42,279,101],{"class":90},[42,281,105],{"class":104},[42,283,108],{"class":90},[20,285,286],{},"This produces:",[33,288,290],{"className":35,"code":289,"language":37,"meta":38,"style":38},"TypeError: 'int' object is not iterable\n",[15,291,292],{"__ignoreMap":38},[42,293,294,298,301,305,308,311,314,317,320],{"class":44,"line":45},[42,295,297],{"class":296},"sZMiF","TypeError",[42,299,300],{"class":90},":",[42,302,304],{"class":303},"sjJ54"," '",[42,306,218],{"class":307},"s_sjI",[42,309,310],{"class":303},"'",[42,312,313],{"class":296}," object",[42,315,316],{"class":52}," is",[42,318,319],{"class":52}," not",[42,321,322],{"class":48}," iterable\n",[20,324,325],{},"Why?",[20,327,328,329,332,333,335],{},"Because ",[15,330,331],{},"10"," is one value, not a sequence of values. A ",[15,334,78],{}," loop needs something it can move through one item at a time.",[28,337,339,340,342],{"id":338},"fix-1-use-range-when-you-want-to-loop-a-number-of-times","Fix 1: Use ",[15,341,160],{}," when you want to loop a number of times",[20,344,345],{},"This is the most common fix for beginners.",[20,347,348,349,352,353,356],{},"If you want to repeat something 5 times, do not loop over ",[15,350,351],{},"5"," directly. Loop over ",[15,354,355],{},"range(5)"," instead.",[33,358,360],{"className":35,"code":359,"language":37,"meta":38,"style":38},"for i in range(5):\n    print(i)\n",[15,361,362,379],{"__ignoreMap":38},[42,363,364,366,369,371,373,375,377],{"class":44,"line":45},[42,365,78],{"class":77},[42,367,368],{"class":48}," i ",[42,370,84],{"class":77},[42,372,131],{"class":97},[42,374,101],{"class":90},[42,376,351],{"class":56},[42,378,139],{"class":90},[42,380,381,383,385,388],{"class":44,"line":60},[42,382,98],{"class":97},[42,384,101],{"class":90},[42,386,387],{"class":104},"i",[42,389,108],{"class":90},[20,391,392],{},"Output:",[33,394,396],{"className":35,"code":395,"language":37,"meta":38,"style":38},"0\n1\n2\n3\n4\n",[15,397,398,403,408,413,418],{"__ignoreMap":38},[42,399,400],{"class":44,"line":45},[42,401,402],{"class":56},"0\n",[42,404,405],{"class":44,"line":60},[42,406,407],{"class":56},"1\n",[42,409,410],{"class":44,"line":67},[42,411,412],{"class":56},"2\n",[42,414,415],{"class":44,"line":74},[42,416,417],{"class":56},"3\n",[42,419,420],{"class":44,"line":94},[42,421,422],{"class":56},"4\n",[20,424,425,427,428,431],{},[15,426,355],{}," creates an iterable that produces the numbers ",[15,429,430],{},"0, 1, 2, 3, 4",".",[20,433,434,435,439,440,431],{},"If you are still learning loops, see ",[155,436,438],{"href":437},"\u002Flearn\u002Fpython-for-loops-explained\u002F","Python for loops explained"," and the ",[155,441,442,444],{"href":157},[15,443,160],{}," function explained",[28,446,448],{"id":447},"fix-2-use-a-real-iterable-when-you-want-to-loop-over-values","Fix 2: Use a real iterable when you want to loop over values",[20,450,451],{},"If you want to loop over several values, store those values in a real iterable such as a list, tuple, or string.",[20,453,454],{},"Wrong:",[33,456,458],{"className":35,"code":457,"language":37,"meta":38,"style":38},"numbers = 123\n\nfor n in numbers:\n    print(n)\n",[15,459,460,470,474,488],{"__ignoreMap":38},[42,461,462,465,467],{"class":44,"line":45},[42,463,464],{"class":48},"numbers ",[42,466,53],{"class":52},[42,468,469],{"class":56}," 123\n",[42,471,472],{"class":44,"line":60},[42,473,64],{"emptyLinePlaceholder":63},[42,475,476,478,481,483,486],{"class":44,"line":67},[42,477,78],{"class":77},[42,479,480],{"class":48}," n ",[42,482,84],{"class":77},[42,484,485],{"class":48}," numbers",[42,487,91],{"class":90},[42,489,490,492,494,497],{"class":44,"line":74},[42,491,98],{"class":97},[42,493,101],{"class":90},[42,495,496],{"class":104},"n",[42,498,108],{"class":90},[20,500,501],{},"Right:",[33,503,505],{"className":35,"code":504,"language":37,"meta":38,"style":38},"numbers = [1, 2, 3]\n\nfor n in numbers:\n    print(n)\n",[15,506,507,533,537,549],{"__ignoreMap":38},[42,508,509,511,513,516,519,522,525,527,530],{"class":44,"line":45},[42,510,464],{"class":48},[42,512,53],{"class":52},[42,514,515],{"class":90}," [",[42,517,518],{"class":56},"1",[42,520,521],{"class":90},",",[42,523,524],{"class":56}," 2",[42,526,521],{"class":90},[42,528,529],{"class":56}," 3",[42,531,532],{"class":90},"]\n",[42,534,535],{"class":44,"line":60},[42,536,64],{"emptyLinePlaceholder":63},[42,538,539,541,543,545,547],{"class":44,"line":67},[42,540,78],{"class":77},[42,542,480],{"class":48},[42,544,84],{"class":77},[42,546,485],{"class":48},[42,548,91],{"class":90},[42,550,551,553,555,557],{"class":44,"line":74},[42,552,98],{"class":97},[42,554,101],{"class":90},[42,556,496],{"class":104},[42,558,108],{"class":90},[20,560,392],{},[33,562,564],{"className":35,"code":563,"language":37,"meta":38,"style":38},"1\n2\n3\n",[15,565,566,570,574],{"__ignoreMap":38},[42,567,568],{"class":44,"line":45},[42,569,407],{"class":56},[42,571,572],{"class":44,"line":60},[42,573,412],{"class":56},[42,575,576],{"class":44,"line":67},[42,577,417],{"class":56},[20,579,580],{},"If you are unsure what your variable contains, print its type:",[33,582,584],{"className":35,"code":583,"language":37,"meta":38,"style":38},"numbers = 123\n\nprint(numbers)\nprint(type(numbers))\n",[15,585,586,594,598,610],{"__ignoreMap":38},[42,587,588,590,592],{"class":44,"line":45},[42,589,464],{"class":48},[42,591,53],{"class":52},[42,593,469],{"class":56},[42,595,596],{"class":44,"line":60},[42,597,64],{"emptyLinePlaceholder":63},[42,599,600,603,605,608],{"class":44,"line":67},[42,601,602],{"class":97},"print",[42,604,101],{"class":90},[42,606,607],{"class":104},"numbers",[42,609,108],{"class":90},[42,611,612,614,616,619,621,623],{"class":44,"line":74},[42,613,602],{"class":97},[42,615,101],{"class":90},[42,617,618],{"class":296},"type",[42,620,101],{"class":90},[42,622,607],{"class":104},[42,624,625],{"class":90},"))\n",[20,627,392],{},[33,629,631],{"className":35,"code":630,"language":37,"meta":38,"style":38},"123\n\u003Cclass 'int'>\n",[15,632,633,638],{"__ignoreMap":38},[42,634,635],{"class":44,"line":45},[42,636,637],{"class":56},"123\n",[42,639,640,643,647,649,651,653],{"class":44,"line":60},[42,641,642],{"class":52},"\u003C",[42,644,646],{"class":645},"sbsja","class",[42,648,304],{"class":303},[42,650,218],{"class":307},[42,652,310],{"class":303},[42,654,655],{"class":52},">\n",[20,657,658,659,431],{},"You can learn more about checking types with the ",[155,660,662,444],{"href":661},"\u002Freference\u002Fpython-type-function-explained\u002F",[15,663,664],{},"type()",[28,666,668],{"id":667},"fix-3-convert-data-before-iterating-if-needed","Fix 3: Convert data before iterating if needed",[20,670,671],{},"Sometimes you really do want to loop over the digits of a number.",[20,673,674],{},"In that case, convert the number to a string first:",[33,676,678],{"className":35,"code":677,"language":37,"meta":38,"style":38},"number = 123\n\nfor digit in str(number):\n    print(digit)\n",[15,679,680,688,692,710],{"__ignoreMap":38},[42,681,682,684,686],{"class":44,"line":45},[42,683,49],{"class":48},[42,685,53],{"class":52},[42,687,469],{"class":56},[42,689,690],{"class":44,"line":60},[42,691,64],{"emptyLinePlaceholder":63},[42,693,694,696,699,701,704,706,708],{"class":44,"line":67},[42,695,78],{"class":77},[42,697,698],{"class":48}," digit ",[42,700,84],{"class":77},[42,702,703],{"class":296}," str",[42,705,101],{"class":90},[42,707,136],{"class":104},[42,709,139],{"class":90},[42,711,712,714,716,719],{"class":44,"line":74},[42,713,98],{"class":97},[42,715,101],{"class":90},[42,717,718],{"class":104},"digit",[42,720,108],{"class":90},[20,722,392],{},[33,724,725],{"className":35,"code":563,"language":37,"meta":38,"style":38},[15,726,727,731,735],{"__ignoreMap":38},[42,728,729],{"class":44,"line":45},[42,730,407],{"class":56},[42,732,733],{"class":44,"line":60},[42,734,412],{"class":56},[42,736,737],{"class":44,"line":67},[42,738,417],{"class":56},[20,740,741,742,745,746,749],{},"This works because ",[15,743,744],{},"str(number)"," becomes ",[15,747,748],{},"\"123\"",", and strings are iterable.",[20,751,752,753,431],{},"Use this only when looping over characters or digits makes sense. If needed, see ",[155,754,756],{"href":755},"\u002Fhow-to\u002Fhow-to-convert-int-to-string-in-python\u002F","how to convert int to string in Python",[28,758,760],{"id":759},"how-to-debug-this-error","How to debug this error",[20,762,763],{},"When this error happens, check the value and type of the variable right before the line that fails.",[20,765,766],{},"Useful debug statements:",[33,768,770],{"className":35,"code":769,"language":37,"meta":38,"style":38},"print(value)\nprint(type(value))\nprint(isinstance(value, int))\nprint(isinstance(value, (list, tuple, str, dict, set, range)))\n",[15,771,772,783,797,817],{"__ignoreMap":38},[42,773,774,776,778,781],{"class":44,"line":45},[42,775,602],{"class":97},[42,777,101],{"class":90},[42,779,780],{"class":104},"value",[42,782,108],{"class":90},[42,784,785,787,789,791,793,795],{"class":44,"line":60},[42,786,602],{"class":97},[42,788,101],{"class":90},[42,790,618],{"class":296},[42,792,101],{"class":90},[42,794,780],{"class":104},[42,796,625],{"class":90},[42,798,799,801,803,806,808,810,812,815],{"class":44,"line":67},[42,800,602],{"class":97},[42,802,101],{"class":90},[42,804,805],{"class":97},"isinstance",[42,807,101],{"class":90},[42,809,780],{"class":104},[42,811,521],{"class":90},[42,813,814],{"class":296}," int",[42,816,625],{"class":90},[42,818,819,821,823,825,827,829,831,834,836,838,841,843,845,847,850,852,855,857,859],{"class":44,"line":74},[42,820,602],{"class":97},[42,822,101],{"class":90},[42,824,805],{"class":97},[42,826,101],{"class":90},[42,828,780],{"class":104},[42,830,521],{"class":90},[42,832,833],{"class":90}," (",[42,835,188],{"class":296},[42,837,521],{"class":90},[42,839,840],{"class":296}," tuple",[42,842,521],{"class":90},[42,844,703],{"class":296},[42,846,521],{"class":90},[42,848,849],{"class":296}," dict",[42,851,521],{"class":90},[42,853,854],{"class":296}," set",[42,856,521],{"class":90},[42,858,131],{"class":97},[42,860,861],{"class":90},")))\n",[20,863,864],{},"A simple debugging example:",[33,866,868],{"className":35,"code":867,"language":37,"meta":38,"style":38},"value = 7\n\nprint(value)\nprint(type(value))\n\nfor item in value:\n    print(item)\n",[15,869,870,880,884,894,908,912,925],{"__ignoreMap":38},[42,871,872,875,877],{"class":44,"line":45},[42,873,874],{"class":48},"value ",[42,876,53],{"class":52},[42,878,879],{"class":56}," 7\n",[42,881,882],{"class":44,"line":60},[42,883,64],{"emptyLinePlaceholder":63},[42,885,886,888,890,892],{"class":44,"line":67},[42,887,602],{"class":97},[42,889,101],{"class":90},[42,891,780],{"class":104},[42,893,108],{"class":90},[42,895,896,898,900,902,904,906],{"class":44,"line":74},[42,897,602],{"class":97},[42,899,101],{"class":90},[42,901,618],{"class":296},[42,903,101],{"class":90},[42,905,780],{"class":104},[42,907,625],{"class":90},[42,909,910],{"class":44,"line":94},[42,911,64],{"emptyLinePlaceholder":63},[42,913,914,916,918,920,923],{"class":44,"line":111},[42,915,78],{"class":77},[42,917,81],{"class":48},[42,919,84],{"class":77},[42,921,922],{"class":48}," value",[42,924,91],{"class":90},[42,926,927,929,931,933],{"class":44,"line":116},[42,928,98],{"class":97},[42,930,101],{"class":90},[42,932,105],{"class":104},[42,934,108],{"class":90},[20,936,937],{},"Output before the error:",[33,939,941],{"className":35,"code":940,"language":37,"meta":38,"style":38},"7\n\u003Cclass 'int'>\n",[15,942,943,948],{"__ignoreMap":38},[42,944,945],{"class":44,"line":45},[42,946,947],{"class":56},"7\n",[42,949,950,952,954,956,958,960],{"class":44,"line":60},[42,951,642],{"class":52},[42,953,646],{"class":645},[42,955,304],{"class":303},[42,957,218],{"class":307},[42,959,310],{"class":303},[42,961,655],{"class":52},[20,963,964],{},"Debugging steps:",[181,966,967,970,977,980],{},[184,968,969],{},"Print the variable before the failing line",[184,971,972,973,976],{},"Use ",[15,974,975],{},"type(variable)"," to confirm its type",[184,978,979],{},"Check where the variable was last assigned",[184,981,982],{},"Look for places where a list or string was overwritten with an integer",[28,984,986],{"id":985},"common-beginner-confusion","Common beginner confusion",[20,988,989],{},"A few similar-looking values behave very differently:",[181,991,992,1000,1009],{},[184,993,994,996,997,999],{},[15,995,355],{}," is iterable, but ",[15,998,351],{}," is not",[184,1001,1002,1003,1005,1006,999],{},"A string like ",[15,1004,748],{}," is iterable, but the integer ",[15,1007,1008],{},"123",[184,1010,1011],{},"A dictionary is iterable, but by default it loops over keys",[20,1013,1014],{},"Example:",[33,1016,1018],{"className":35,"code":1017,"language":37,"meta":38,"style":38},"for ch in \"123\":\n    print(ch)\n",[15,1019,1020,1039],{"__ignoreMap":38},[42,1021,1022,1024,1027,1029,1032,1034,1037],{"class":44,"line":45},[42,1023,78],{"class":77},[42,1025,1026],{"class":48}," ch ",[42,1028,84],{"class":77},[42,1030,1031],{"class":303}," \"",[42,1033,1008],{"class":307},[42,1035,1036],{"class":303},"\"",[42,1038,91],{"class":90},[42,1040,1041,1043,1045,1048],{"class":44,"line":60},[42,1042,98],{"class":97},[42,1044,101],{"class":90},[42,1046,1047],{"class":104},"ch",[42,1049,108],{"class":90},[20,1051,1052],{},"This works because a string can be iterated over one character at a time.",[28,1054,1056],{"id":1055},"common-causes","Common causes",[20,1058,1059],{},"Here are the most common reasons for this error:",[181,1061,1062,1067,1070,1090,1093],{},[184,1063,1064,1065],{},"Looping over an integer with ",[15,1066,78],{},[184,1068,1069],{},"Using membership testing with an integer",[184,1071,1072,1073,1075,1076,1079,1080,1079,1083,1079,1086,1089],{},"Passing an ",[15,1074,218],{}," into ",[15,1077,1078],{},"list()",", ",[15,1081,1082],{},"sum()",[15,1084,1085],{},"any()",[15,1087,1088],{},"all()",", or similar functions incorrectly",[184,1091,1092],{},"Reusing a variable name so a list becomes an integer",[184,1094,1095,1096,1098],{},"Converting user input to ",[15,1097,218],{}," before code that expected a string or list",[20,1100,1101],{},"Example of variable reuse causing the problem:",[33,1103,1105],{"className":35,"code":1104,"language":37,"meta":38,"style":38},"items = [\"a\", \"b\", \"c\"]\nitems = 3\n\nfor item in items:\n    print(item)\n",[15,1106,1107,1142,1151,1155,1168],{"__ignoreMap":38},[42,1108,1109,1112,1114,1116,1118,1120,1122,1124,1126,1129,1131,1133,1135,1138,1140],{"class":44,"line":45},[42,1110,1111],{"class":48},"items ",[42,1113,53],{"class":52},[42,1115,515],{"class":90},[42,1117,1036],{"class":303},[42,1119,155],{"class":307},[42,1121,1036],{"class":303},[42,1123,521],{"class":90},[42,1125,1031],{"class":303},[42,1127,1128],{"class":307},"b",[42,1130,1036],{"class":303},[42,1132,521],{"class":90},[42,1134,1031],{"class":303},[42,1136,1137],{"class":307},"c",[42,1139,1036],{"class":303},[42,1141,532],{"class":90},[42,1143,1144,1146,1148],{"class":44,"line":60},[42,1145,1111],{"class":48},[42,1147,53],{"class":52},[42,1149,1150],{"class":56}," 3\n",[42,1152,1153],{"class":44,"line":67},[42,1154,64],{"emptyLinePlaceholder":63},[42,1156,1157,1159,1161,1163,1166],{"class":44,"line":74},[42,1158,78],{"class":77},[42,1160,81],{"class":48},[42,1162,84],{"class":77},[42,1164,1165],{"class":48}," items",[42,1167,91],{"class":90},[42,1169,1170,1172,1174,1176],{"class":44,"line":94},[42,1171,98],{"class":97},[42,1173,101],{"class":90},[42,1175,105],{"class":104},[42,1177,108],{"class":90},[20,1179,1180,1181,1184],{},"The variable ",[15,1182,1183],{},"items"," started as a list, but later it was changed to an integer.",[28,1186,1188],{"id":1187},"faq","FAQ",[1190,1191,1193],"h3",{"id":1192},"what-does-iterable-mean-in-python","What does iterable mean in Python?",[20,1195,1196,1197,431],{},"An iterable is an object you can loop over, such as a list, tuple, string, dictionary, set, or ",[15,1198,213],{},[1190,1200,1202,1203,1205,1206,1208],{"id":1201},"why-does-range5-work-but-5-does-not","Why does ",[15,1204,355],{}," work but ",[15,1207,351],{}," does not?",[20,1210,1211,1213,1214,1216],{},[15,1212,355],{}," creates an iterable sequence of numbers. The integer ",[15,1215,351],{}," is only one value.",[1190,1218,1220],{"id":1219},"can-i-iterate-over-the-digits-of-an-integer","Can I iterate over the digits of an integer?",[20,1222,1223,1224,1227],{},"Yes. Convert it first, such as ",[15,1225,1226],{},"str(123)",", if you want to loop over each digit as a character.",[1190,1229,1231],{"id":1230},"how-do-i-loop-10-times-in-python","How do I loop 10 times in Python?",[20,1233,1234],{},"Use:",[33,1236,1238],{"className":35,"code":1237,"language":37,"meta":38,"style":38},"for i in range(10):\n    print(i)\n",[15,1239,1240,1256],{"__ignoreMap":38},[42,1241,1242,1244,1246,1248,1250,1252,1254],{"class":44,"line":45},[42,1243,78],{"class":77},[42,1245,368],{"class":48},[42,1247,84],{"class":77},[42,1249,131],{"class":97},[42,1251,101],{"class":90},[42,1253,331],{"class":56},[42,1255,139],{"class":90},[42,1257,1258,1260,1262,1264],{"class":44,"line":60},[42,1259,98],{"class":97},[42,1261,101],{"class":90},[42,1263,387],{"class":104},[42,1265,108],{"class":90},[20,1267,1268],{},"not:",[33,1270,1272],{"className":35,"code":1271,"language":37,"meta":38,"style":38},"for i in 10:\n    print(i)\n",[15,1273,1274,1286],{"__ignoreMap":38},[42,1275,1276,1278,1280,1282,1284],{"class":44,"line":45},[42,1277,78],{"class":77},[42,1279,368],{"class":48},[42,1281,84],{"class":77},[42,1283,271],{"class":56},[42,1285,91],{"class":90},[42,1287,1288,1290,1292,1294],{"class":44,"line":60},[42,1289,98],{"class":97},[42,1291,101],{"class":90},[42,1293,387],{"class":104},[42,1295,108],{"class":90},[28,1297,1299],{"id":1298},"see-also","See also",[181,1301,1302,1306,1313,1319,1324,1332,1340],{},[184,1303,1304],{},[155,1305,438],{"href":437},[184,1307,1308],{},[155,1309,1310,1311,444],{"href":157},"Python ",[15,1312,160],{},[184,1314,1315],{},[155,1316,1310,1317,444],{"href":661},[15,1318,664],{},[184,1320,1321],{},[155,1322,1323],{"href":755},"How to convert int to string in Python",[184,1325,1326],{},[155,1327,13,1329,18],{"href":1328},"\u002Ferrors\u002Ftypeerror-function-object-is-not-iterable-fix\u002F",[15,1330,1331],{},"'function' object is not iterable",[184,1333,1334],{},[155,1335,13,1337,18],{"href":1336},"\u002Ferrors\u002Ftypeerror-bool-object-is-not-iterable-fix\u002F",[15,1338,1339],{},"'bool' object is not iterable",[184,1341,1342],{},[155,1343,13,1345,18],{"href":1344},"\u002Ferrors\u002Ftypeerror-nonetype-object-is-not-iterable-fix\u002F",[15,1346,1347],{},"'NoneType' object is not iterable",[20,1349,1350,1351,1353],{},"Check the variable type first, then decide whether you should use ",[15,1352,160],{}," or a real iterable. That usually leads you to the correct fix quickly.",[1355,1356,1357],"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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}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 .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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 .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":38,"searchDepth":60,"depth":60,"links":1359},[1360,1361,1362,1363,1364,1366,1367,1368,1369,1370,1371,1378],{"id":30,"depth":60,"text":31},{"id":164,"depth":60,"text":165},{"id":222,"depth":60,"text":223},{"id":251,"depth":60,"text":252},{"id":338,"depth":60,"text":1365},"Fix 1: Use range() when you want to loop a number of times",{"id":447,"depth":60,"text":448},{"id":667,"depth":60,"text":668},{"id":759,"depth":60,"text":760},{"id":985,"depth":60,"text":986},{"id":1055,"depth":60,"text":1056},{"id":1187,"depth":60,"text":1188,"children":1372},[1373,1374,1376,1377],{"id":1192,"depth":67,"text":1193},{"id":1201,"depth":67,"text":1375},"Why does range(5) work but 5 does not?",{"id":1219,"depth":67,"text":1220},{"id":1230,"depth":67,"text":1231},{"id":1298,"depth":60,"text":1299},"Master typeerror int object is not iterable fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Ftypeerror-int-object-is-not-iterable-fix",{"title":5,"description":1379},"errors\u002Ftypeerror-int-object-is-not-iterable-fix","V4wq_bZVfl6xnqtf8l1bswFGxrL7tzN4daGu3k6lMMY",1777585502529]