[{"data":1,"prerenderedAt":1964},["ShallowReactive",2],{"doc-\u002Ferrors\u002Ftypeerror-function-object-is-not-iterable-fix":3},{"id":4,"title":5,"body":6,"description":1957,"extension":1958,"meta":1959,"navigation":101,"path":1960,"seo":1961,"stem":1962,"__hash__":1963},"content\u002Ferrors\u002Ftypeerror-function-object-is-not-iterable-fix.md","TypeError: 'function' object is not iterable (Fix)",{"type":7,"value":8,"toc":1919},"minimark",[9,19,30,37,42,137,140,144,151,176,183,190,203,207,210,250,254,257,315,318,356,361,375,382,386,389,445,447,467,470,473,487,491,494,497,544,551,555,558,623,625,653,666,669,725,736,740,743,746,835,842,846,849,931,934,991,994,998,1001,1007,1075,1082,1143,1153,1199,1204,1256,1259,1312,1316,1319,1334,1337,1405,1409,1508,1510,1577,1580,1592,1599,1603,1606,1638,1641,1718,1727,1731,1808,1812,1816,1819,1823,1831,1835,1838,1842,1845,1870,1874,1915],[10,11,13,14,18],"h1",{"id":12},"typeerror-function-object-is-not-iterable-fix","TypeError: ",[15,16,17],"code",{},"'function' object is not iterable"," (Fix)",[20,21,22,23,29],"p",{},"Fix the Python error ",[24,25,26],"strong",{},[15,27,28],{},"TypeError: 'function' object is not iterable",". This error usually means Python expected something it could loop over, but you gave it a function itself instead of the value returned by that function.",[20,31,32,33,36],{},"In most cases, the fix is simple: ",[24,34,35],{},"call the function with parentheses",".",[38,39,41],"h2",{"id":40},"quick-fix","Quick fix",[43,44,49],"pre",{"className":45,"code":46,"language":47,"meta":48,"style":48},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","def get_numbers():\n    return [1, 2, 3]\n\nfor n in get_numbers():\n    print(n)\n","python","",[15,50,51,68,96,103,121],{"__ignoreMap":48},[52,53,56,60,64],"span",{"class":54,"line":55},"line",1,[52,57,59],{"class":58},"sbsja","def",[52,61,63],{"class":62},"sGLFI"," get_numbers",[52,65,67],{"class":66},"sP7_E","():\n",[52,69,71,75,78,82,85,88,90,93],{"class":54,"line":70},2,[52,72,74],{"class":73},"sVHd0","    return",[52,76,77],{"class":66}," [",[52,79,81],{"class":80},"srdBf","1",[52,83,84],{"class":66},",",[52,86,87],{"class":80}," 2",[52,89,84],{"class":66},[52,91,92],{"class":80}," 3",[52,94,95],{"class":66},"]\n",[52,97,99],{"class":54,"line":98},3,[52,100,102],{"emptyLinePlaceholder":101},true,"\n",[52,104,106,109,113,116,119],{"class":54,"line":105},4,[52,107,108],{"class":73},"for",[52,110,112],{"class":111},"su5hD"," n ",[52,114,115],{"class":73},"in",[52,117,63],{"class":118},"slqww",[52,120,67],{"class":66},[52,122,124,128,131,134],{"class":54,"line":123},5,[52,125,127],{"class":126},"sptTA","    print",[52,129,130],{"class":66},"(",[52,132,133],{"class":118},"n",[52,135,136],{"class":66},")\n",[20,138,139],{},"This error often happens when you loop over a function name instead of the value returned by the function. Add parentheses if you meant to call the function.",[38,141,143],{"id":142},"what-this-error-means","What this error means",[20,145,146,147,150],{},"Python expected an ",[24,148,149],{},"iterable"," object, such as:",[152,153,154,158,161,164,167,170],"ul",{},[155,156,157],"li",{},"a list",[155,159,160],{},"a tuple",[155,162,163],{},"a string",[155,165,166],{},"a set",[155,168,169],{},"a dictionary",[155,171,172,173],{},"a ",[15,174,175],{},"range",[20,177,178,179,182],{},"But it got a ",[24,180,181],{},"function object"," instead.",[20,184,185,186,189],{},"A function is something you ",[24,187,188],{},"call"," to get a result. It is not something you can loop over directly.",[20,191,192,193,198,199,36],{},"If you are not fully comfortable with functions yet, see ",[194,195,197],"a",{"href":196},"\u002Flearn\u002Fpython-functions-explained\u002F","Python functions explained"," and ",[194,200,202],{"href":201},"\u002Flearn\u002Fiterators-and-iterable-objects-explained\u002F","iterators and iterable objects explained",[38,204,206],{"id":205},"why-this-happens","Why this happens",[20,208,209],{},"This error usually appears when:",[152,211,212,218,224,247],{},[155,213,214,215],{},"You wrote a function name ",[24,216,217],{},"without parentheses",[155,219,220,221,223],{},"You used a function in a ",[15,222,108],{}," loop",[155,225,226,227,230,231,230,234,230,237,230,240,230,243,246],{},"You used a function with ",[15,228,229],{},"list()",", ",[15,232,233],{},"tuple()",[15,235,236],{},"set()",[15,238,239],{},"sum()",[15,241,242],{},"any()",[15,244,245],{},"all()",", or similar code that expects an iterable",[155,248,249],{},"You returned a function instead of returning data by mistake",[38,251,253],{"id":252},"common-example-that-causes-the-error","Common example that causes the error",[20,255,256],{},"Here is a simple example:",[43,258,260],{"className":45,"code":259,"language":47,"meta":48,"style":48},"def get_numbers():\n    return [1, 2, 3]\n\nfor n in get_numbers:\n    print(n)\n",[15,261,262,270,288,292,305],{"__ignoreMap":48},[52,263,264,266,268],{"class":54,"line":55},[52,265,59],{"class":58},[52,267,63],{"class":62},[52,269,67],{"class":66},[52,271,272,274,276,278,280,282,284,286],{"class":54,"line":70},[52,273,74],{"class":73},[52,275,77],{"class":66},[52,277,81],{"class":80},[52,279,84],{"class":66},[52,281,87],{"class":80},[52,283,84],{"class":66},[52,285,92],{"class":80},[52,287,95],{"class":66},[52,289,290],{"class":54,"line":98},[52,291,102],{"emptyLinePlaceholder":101},[52,293,294,296,298,300,302],{"class":54,"line":105},[52,295,108],{"class":73},[52,297,112],{"class":111},[52,299,115],{"class":73},[52,301,63],{"class":111},[52,303,304],{"class":66},":\n",[52,306,307,309,311,313],{"class":54,"line":123},[52,308,127],{"class":126},[52,310,130],{"class":66},[52,312,133],{"class":118},[52,314,136],{"class":66},[20,316,317],{},"Output:",[43,319,321],{"className":45,"code":320,"language":47,"meta":48,"style":48},"TypeError: 'function' object is not iterable\n",[15,322,323],{"__ignoreMap":48},[52,324,325,329,332,336,340,343,346,350,353],{"class":54,"line":55},[52,326,328],{"class":327},"sZMiF","TypeError",[52,330,331],{"class":66},":",[52,333,335],{"class":334},"sjJ54"," '",[52,337,339],{"class":338},"s_sjI","function",[52,341,342],{"class":334},"'",[52,344,345],{"class":327}," object",[52,347,349],{"class":348},"smGrS"," is",[52,351,352],{"class":348}," not",[52,354,355],{"class":111}," iterable\n",[357,358,360],"h3",{"id":359},"why-this-fails","Why this fails",[152,362,363,369],{},[155,364,365,368],{},[15,366,367],{},"get_numbers"," is the function itself",[155,370,371,374],{},[15,372,373],{},"get_numbers()"," is the list returned by the function",[20,376,377,378,381],{},"Python cannot loop over the function object, but it ",[24,379,380],{},"can"," loop over the list returned by the function.",[38,383,385],{"id":384},"fix-1-call-the-function","Fix 1: Call the function",[20,387,388],{},"If you want the function's result, add parentheses.",[43,390,391],{"className":45,"code":46,"language":47,"meta":48,"style":48},[15,392,393,401,419,423,435],{"__ignoreMap":48},[52,394,395,397,399],{"class":54,"line":55},[52,396,59],{"class":58},[52,398,63],{"class":62},[52,400,67],{"class":66},[52,402,403,405,407,409,411,413,415,417],{"class":54,"line":70},[52,404,74],{"class":73},[52,406,77],{"class":66},[52,408,81],{"class":80},[52,410,84],{"class":66},[52,412,87],{"class":80},[52,414,84],{"class":66},[52,416,92],{"class":80},[52,418,95],{"class":66},[52,420,421],{"class":54,"line":98},[52,422,102],{"emptyLinePlaceholder":101},[52,424,425,427,429,431,433],{"class":54,"line":105},[52,426,108],{"class":73},[52,428,112],{"class":111},[52,430,115],{"class":73},[52,432,63],{"class":118},[52,434,67],{"class":66},[52,436,437,439,441,443],{"class":54,"line":123},[52,438,127],{"class":126},[52,440,130],{"class":66},[52,442,133],{"class":118},[52,444,136],{"class":66},[20,446,317],{},[43,448,450],{"className":45,"code":449,"language":47,"meta":48,"style":48},"1\n2\n3\n",[15,451,452,457,462],{"__ignoreMap":48},[52,453,454],{"class":54,"line":55},[52,455,456],{"class":80},"1\n",[52,458,459],{"class":54,"line":70},[52,460,461],{"class":80},"2\n",[52,463,464],{"class":54,"line":98},[52,465,466],{"class":80},"3\n",[20,468,469],{},"This is the most common fix.",[20,471,472],{},"Use:",[152,474,475,481],{},[155,476,477,480],{},[15,478,479],{},"my_function()"," if you want the returned value",[155,482,483,486],{},[15,484,485],{},"my_function"," only when you want to refer to the function itself",[38,488,490],{"id":489},"fix-2-check-what-the-function-returns","Fix 2: Check what the function returns",[20,492,493],{},"Sometimes you already called the function, but the returned value still is not iterable.",[20,495,496],{},"For example:",[43,498,500],{"className":45,"code":499,"language":47,"meta":48,"style":48},"def get_total():\n    return 10\n\nfor n in get_total():\n    print(n)\n",[15,501,502,511,518,522,534],{"__ignoreMap":48},[52,503,504,506,509],{"class":54,"line":55},[52,505,59],{"class":58},[52,507,508],{"class":62}," get_total",[52,510,67],{"class":66},[52,512,513,515],{"class":54,"line":70},[52,514,74],{"class":73},[52,516,517],{"class":80}," 10\n",[52,519,520],{"class":54,"line":98},[52,521,102],{"emptyLinePlaceholder":101},[52,523,524,526,528,530,532],{"class":54,"line":105},[52,525,108],{"class":73},[52,527,112],{"class":111},[52,529,115],{"class":73},[52,531,508],{"class":118},[52,533,67],{"class":66},[52,535,536,538,540,542],{"class":54,"line":123},[52,537,127],{"class":126},[52,539,130],{"class":66},[52,541,133],{"class":118},[52,543,136],{"class":66},[20,545,546,547,550],{},"This also fails, because ",[15,548,549],{},"10"," is an integer, and integers are not iterable.",[357,552,554],{"id":553},"how-to-debug-it","How to debug it",[20,556,557],{},"Check the returned value and its type:",[43,559,561],{"className":45,"code":560,"language":47,"meta":48,"style":48},"def get_total():\n    return 10\n\nvalue = get_total()\nprint(value)\nprint(type(value))\n",[15,562,563,571,577,581,594,606],{"__ignoreMap":48},[52,564,565,567,569],{"class":54,"line":55},[52,566,59],{"class":58},[52,568,508],{"class":62},[52,570,67],{"class":66},[52,572,573,575],{"class":54,"line":70},[52,574,74],{"class":73},[52,576,517],{"class":80},[52,578,579],{"class":54,"line":98},[52,580,102],{"emptyLinePlaceholder":101},[52,582,583,586,589,591],{"class":54,"line":105},[52,584,585],{"class":111},"value ",[52,587,588],{"class":348},"=",[52,590,508],{"class":118},[52,592,593],{"class":66},"()\n",[52,595,596,599,601,604],{"class":54,"line":123},[52,597,598],{"class":126},"print",[52,600,130],{"class":66},[52,602,603],{"class":118},"value",[52,605,136],{"class":66},[52,607,609,611,613,616,618,620],{"class":54,"line":608},6,[52,610,598],{"class":126},[52,612,130],{"class":66},[52,614,615],{"class":327},"type",[52,617,130],{"class":66},[52,619,603],{"class":118},[52,621,622],{"class":66},"))\n",[20,624,317],{},[43,626,628],{"className":45,"code":627,"language":47,"meta":48,"style":48},"10\n\u003Cclass 'int'>\n",[15,629,630,635],{"__ignoreMap":48},[52,631,632],{"class":54,"line":55},[52,633,634],{"class":80},"10\n",[52,636,637,640,643,645,648,650],{"class":54,"line":70},[52,638,639],{"class":348},"\u003C",[52,641,642],{"class":58},"class",[52,644,335],{"class":334},[52,646,647],{"class":338},"int",[52,649,342],{"class":334},[52,651,652],{"class":348},">\n",[20,654,655,656,230,659,661,662,665],{},"If the function returns ",[15,657,658],{},"None",[15,660,647],{},", or ",[15,663,664],{},"bool",", you still cannot iterate over it.",[20,667,668],{},"A function must return something iterable, such as a list or tuple:",[43,670,672],{"className":45,"code":671,"language":47,"meta":48,"style":48},"def get_total_parts():\n    return [3, 7]\n\nfor n in get_total_parts():\n    print(n)\n",[15,673,674,683,699,703,715],{"__ignoreMap":48},[52,675,676,678,681],{"class":54,"line":55},[52,677,59],{"class":58},[52,679,680],{"class":62}," get_total_parts",[52,682,67],{"class":66},[52,684,685,687,689,692,694,697],{"class":54,"line":70},[52,686,74],{"class":73},[52,688,77],{"class":66},[52,690,691],{"class":80},"3",[52,693,84],{"class":66},[52,695,696],{"class":80}," 7",[52,698,95],{"class":66},[52,700,701],{"class":54,"line":98},[52,702,102],{"emptyLinePlaceholder":101},[52,704,705,707,709,711,713],{"class":54,"line":105},[52,706,108],{"class":73},[52,708,112],{"class":111},[52,710,115],{"class":73},[52,712,680],{"class":118},[52,714,67],{"class":66},[52,716,717,719,721,723],{"class":54,"line":123},[52,718,127],{"class":126},[52,720,130],{"class":66},[52,722,133],{"class":118},[52,724,136],{"class":66},[20,726,727,728,36],{},"If you need help checking types, see ",[194,729,731,732,735],{"href":730},"\u002Freference\u002Fpython-type-function-explained\u002F","Python ",[15,733,734],{},"type()"," explained",[38,737,739],{"id":738},"fix-3-do-not-overwrite-iterable-variables-with-functions","Fix 3: Do not overwrite iterable variables with functions",[20,741,742],{},"Sometimes the problem is caused by reusing the same name for different things.",[20,744,745],{},"Example:",[43,747,749],{"className":45,"code":748,"language":47,"meta":48,"style":48},"items = [1, 2, 3]\n\ndef items():\n    return [4, 5, 6]\n\nfor x in items:\n    print(x)\n",[15,750,751,772,776,785,806,810,823],{"__ignoreMap":48},[52,752,753,756,758,760,762,764,766,768,770],{"class":54,"line":55},[52,754,755],{"class":111},"items ",[52,757,588],{"class":348},[52,759,77],{"class":66},[52,761,81],{"class":80},[52,763,84],{"class":66},[52,765,87],{"class":80},[52,767,84],{"class":66},[52,769,92],{"class":80},[52,771,95],{"class":66},[52,773,774],{"class":54,"line":70},[52,775,102],{"emptyLinePlaceholder":101},[52,777,778,780,783],{"class":54,"line":98},[52,779,59],{"class":58},[52,781,782],{"class":62}," items",[52,784,67],{"class":66},[52,786,787,789,791,794,796,799,801,804],{"class":54,"line":105},[52,788,74],{"class":73},[52,790,77],{"class":66},[52,792,793],{"class":80},"4",[52,795,84],{"class":66},[52,797,798],{"class":80}," 5",[52,800,84],{"class":66},[52,802,803],{"class":80}," 6",[52,805,95],{"class":66},[52,807,808],{"class":54,"line":123},[52,809,102],{"emptyLinePlaceholder":101},[52,811,812,814,817,819,821],{"class":54,"line":608},[52,813,108],{"class":73},[52,815,816],{"class":111}," x ",[52,818,115],{"class":73},[52,820,782],{"class":111},[52,822,304],{"class":66},[52,824,826,828,830,833],{"class":54,"line":825},7,[52,827,127],{"class":126},[52,829,130],{"class":66},[52,831,832],{"class":118},"x",[52,834,136],{"class":66},[20,836,837,838,841],{},"This fails because ",[15,839,840],{},"items"," now refers to the function, not the original list.",[357,843,845],{"id":844},"better-version","Better version",[20,847,848],{},"Use different names:",[43,850,852],{"className":45,"code":851,"language":47,"meta":48,"style":48},"items = [1, 2, 3]\n\ndef get_items():\n    return [4, 5, 6]\n\nfor x in items:\n    print(x)\n",[15,853,854,874,878,887,905,909,921],{"__ignoreMap":48},[52,855,856,858,860,862,864,866,868,870,872],{"class":54,"line":55},[52,857,755],{"class":111},[52,859,588],{"class":348},[52,861,77],{"class":66},[52,863,81],{"class":80},[52,865,84],{"class":66},[52,867,87],{"class":80},[52,869,84],{"class":66},[52,871,92],{"class":80},[52,873,95],{"class":66},[52,875,876],{"class":54,"line":70},[52,877,102],{"emptyLinePlaceholder":101},[52,879,880,882,885],{"class":54,"line":98},[52,881,59],{"class":58},[52,883,884],{"class":62}," get_items",[52,886,67],{"class":66},[52,888,889,891,893,895,897,899,901,903],{"class":54,"line":105},[52,890,74],{"class":73},[52,892,77],{"class":66},[52,894,793],{"class":80},[52,896,84],{"class":66},[52,898,798],{"class":80},[52,900,84],{"class":66},[52,902,803],{"class":80},[52,904,95],{"class":66},[52,906,907],{"class":54,"line":123},[52,908,102],{"emptyLinePlaceholder":101},[52,910,911,913,915,917,919],{"class":54,"line":608},[52,912,108],{"class":73},[52,914,816],{"class":111},[52,916,115],{"class":73},[52,918,782],{"class":111},[52,920,304],{"class":66},[52,922,923,925,927,929],{"class":54,"line":825},[52,924,127],{"class":126},[52,926,130],{"class":66},[52,928,832],{"class":118},[52,930,136],{"class":66},[20,932,933],{},"Or, if you want the function result:",[43,935,937],{"className":45,"code":936,"language":47,"meta":48,"style":48},"def get_items():\n    return [4, 5, 6]\n\nfor x in get_items():\n    print(x)\n",[15,938,939,947,965,969,981],{"__ignoreMap":48},[52,940,941,943,945],{"class":54,"line":55},[52,942,59],{"class":58},[52,944,884],{"class":62},[52,946,67],{"class":66},[52,948,949,951,953,955,957,959,961,963],{"class":54,"line":70},[52,950,74],{"class":73},[52,952,77],{"class":66},[52,954,793],{"class":80},[52,956,84],{"class":66},[52,958,798],{"class":80},[52,960,84],{"class":66},[52,962,803],{"class":80},[52,964,95],{"class":66},[52,966,967],{"class":54,"line":98},[52,968,102],{"emptyLinePlaceholder":101},[52,970,971,973,975,977,979],{"class":54,"line":105},[52,972,108],{"class":73},[52,974,816],{"class":111},[52,976,115],{"class":73},[52,978,884],{"class":118},[52,980,67],{"class":66},[52,982,983,985,987,989],{"class":54,"line":123},[52,984,127],{"class":126},[52,986,130],{"class":66},[52,988,832],{"class":118},[52,990,136],{"class":66},[20,992,993],{},"Clear names help prevent this kind of mistake.",[38,995,997],{"id":996},"where-this-error-appears","Where this error appears",[20,999,1000],{},"You may see this error in places like these:",[357,1002,1004,1005,223],{"id":1003},"in-a-for-loop","In a ",[15,1006,108],{},[43,1008,1010],{"className":45,"code":1009,"language":47,"meta":48,"style":48},"def names():\n    return [\"Ana\", \"Ben\"]\n\nfor name in names:\n    print(name)\n",[15,1011,1012,1021,1047,1051,1064],{"__ignoreMap":48},[52,1013,1014,1016,1019],{"class":54,"line":55},[52,1015,59],{"class":58},[52,1017,1018],{"class":62}," names",[52,1020,67],{"class":66},[52,1022,1023,1025,1027,1030,1033,1035,1037,1040,1043,1045],{"class":54,"line":70},[52,1024,74],{"class":73},[52,1026,77],{"class":66},[52,1028,1029],{"class":334},"\"",[52,1031,1032],{"class":338},"Ana",[52,1034,1029],{"class":334},[52,1036,84],{"class":66},[52,1038,1039],{"class":334}," \"",[52,1041,1042],{"class":338},"Ben",[52,1044,1029],{"class":334},[52,1046,95],{"class":66},[52,1048,1049],{"class":54,"line":98},[52,1050,102],{"emptyLinePlaceholder":101},[52,1052,1053,1055,1058,1060,1062],{"class":54,"line":105},[52,1054,108],{"class":73},[52,1056,1057],{"class":111}," name ",[52,1059,115],{"class":73},[52,1061,1018],{"class":111},[52,1063,304],{"class":66},[52,1065,1066,1068,1070,1073],{"class":54,"line":123},[52,1067,127],{"class":126},[52,1069,130],{"class":66},[52,1071,1072],{"class":118},"name",[52,1074,136],{"class":66},[357,1076,1078,1079,1081],{"id":1077},"with-the-in-operator","With the ",[15,1080,115],{}," operator",[43,1083,1085],{"className":45,"code":1084,"language":47,"meta":48,"style":48},"def colors():\n    return [\"red\", \"blue\"]\n\nprint(\"red\" in colors)\n",[15,1086,1087,1096,1120,1124],{"__ignoreMap":48},[52,1088,1089,1091,1094],{"class":54,"line":55},[52,1090,59],{"class":58},[52,1092,1093],{"class":62}," colors",[52,1095,67],{"class":66},[52,1097,1098,1100,1102,1104,1107,1109,1111,1113,1116,1118],{"class":54,"line":70},[52,1099,74],{"class":73},[52,1101,77],{"class":66},[52,1103,1029],{"class":334},[52,1105,1106],{"class":338},"red",[52,1108,1029],{"class":334},[52,1110,84],{"class":66},[52,1112,1039],{"class":334},[52,1114,1115],{"class":338},"blue",[52,1117,1029],{"class":334},[52,1119,95],{"class":66},[52,1121,1122],{"class":54,"line":98},[52,1123,102],{"emptyLinePlaceholder":101},[52,1125,1126,1128,1130,1132,1134,1136,1139,1141],{"class":54,"line":105},[52,1127,598],{"class":126},[52,1129,130],{"class":66},[52,1131,1029],{"class":334},[52,1133,1106],{"class":338},[52,1135,1029],{"class":334},[52,1137,1138],{"class":73}," in",[52,1140,1093],{"class":118},[52,1142,136],{"class":66},[357,1144,1146,1147,230,1149,661,1151],{"id":1145},"with-list-tuple-or-set","With ",[15,1148,229],{},[15,1150,233],{},[15,1152,236],{},[43,1154,1156],{"className":45,"code":1155,"language":47,"meta":48,"style":48},"def letters():\n    return \"abc\"\n\nprint(list(letters))\n",[15,1157,1158,1167,1179,1183],{"__ignoreMap":48},[52,1159,1160,1162,1165],{"class":54,"line":55},[52,1161,59],{"class":58},[52,1163,1164],{"class":62}," letters",[52,1166,67],{"class":66},[52,1168,1169,1171,1173,1176],{"class":54,"line":70},[52,1170,74],{"class":73},[52,1172,1039],{"class":334},[52,1174,1175],{"class":338},"abc",[52,1177,1178],{"class":334},"\"\n",[52,1180,1181],{"class":54,"line":98},[52,1182,102],{"emptyLinePlaceholder":101},[52,1184,1185,1187,1189,1192,1194,1197],{"class":54,"line":105},[52,1186,598],{"class":126},[52,1188,130],{"class":66},[52,1190,1191],{"class":327},"list",[52,1193,130],{"class":66},[52,1195,1196],{"class":118},"letters",[52,1198,622],{"class":66},[357,1200,1146,1202],{"id":1201},"with-sum",[15,1203,239],{},[43,1205,1207],{"className":45,"code":1206,"language":47,"meta":48,"style":48},"def numbers():\n    return [1, 2, 3]\n\nprint(sum(numbers))\n",[15,1208,1209,1218,1236,1240],{"__ignoreMap":48},[52,1210,1211,1213,1216],{"class":54,"line":55},[52,1212,59],{"class":58},[52,1214,1215],{"class":62}," numbers",[52,1217,67],{"class":66},[52,1219,1220,1222,1224,1226,1228,1230,1232,1234],{"class":54,"line":70},[52,1221,74],{"class":73},[52,1223,77],{"class":66},[52,1225,81],{"class":80},[52,1227,84],{"class":66},[52,1229,87],{"class":80},[52,1231,84],{"class":66},[52,1233,92],{"class":80},[52,1235,95],{"class":66},[52,1237,1238],{"class":54,"line":98},[52,1239,102],{"emptyLinePlaceholder":101},[52,1241,1242,1244,1246,1249,1251,1254],{"class":54,"line":105},[52,1243,598],{"class":126},[52,1245,130],{"class":66},[52,1247,1248],{"class":126},"sum",[52,1250,130],{"class":66},[52,1252,1253],{"class":118},"numbers",[52,1255,622],{"class":66},[20,1257,1258],{},"In all of these cases, the fix is usually to call the function:",[43,1260,1262],{"className":45,"code":1261,"language":47,"meta":48,"style":48},"print(\"red\" in colors())\nprint(list(letters()))\nprint(sum(numbers()))\n",[15,1263,1264,1283,1298],{"__ignoreMap":48},[52,1265,1266,1268,1270,1272,1274,1276,1278,1280],{"class":54,"line":55},[52,1267,598],{"class":126},[52,1269,130],{"class":66},[52,1271,1029],{"class":334},[52,1273,1106],{"class":338},[52,1275,1029],{"class":334},[52,1277,1138],{"class":73},[52,1279,1093],{"class":118},[52,1281,1282],{"class":66},"())\n",[52,1284,1285,1287,1289,1291,1293,1295],{"class":54,"line":70},[52,1286,598],{"class":126},[52,1288,130],{"class":66},[52,1290,1191],{"class":327},[52,1292,130],{"class":66},[52,1294,1196],{"class":118},[52,1296,1297],{"class":66},"()))\n",[52,1299,1300,1302,1304,1306,1308,1310],{"class":54,"line":98},[52,1301,598],{"class":126},[52,1303,130],{"class":66},[52,1305,1248],{"class":126},[52,1307,130],{"class":66},[52,1309,1253],{"class":118},[52,1311,1297],{"class":66},[38,1313,1315],{"id":1314},"beginner-debugging-steps","Beginner debugging steps",[20,1317,1318],{},"When you see this error, use these steps:",[1320,1321,1322,1325,1328,1331],"ol",{},[155,1323,1324],{},"Find the exact line shown in the traceback",[155,1326,1327],{},"Check whether you used a function name without parentheses",[155,1329,1330],{},"Print the object and its type before the failing line",[155,1332,1333],{},"Confirm that the value is actually iterable",[20,1335,1336],{},"Useful debugging code:",[43,1338,1340],{"className":45,"code":1339,"language":47,"meta":48,"style":48},"print(my_function)\nprint(type(my_function))\n\nvalue = my_function()\nprint(value)\nprint(type(value))\n",[15,1341,1342,1352,1366,1370,1381,1391],{"__ignoreMap":48},[52,1343,1344,1346,1348,1350],{"class":54,"line":55},[52,1345,598],{"class":126},[52,1347,130],{"class":66},[52,1349,485],{"class":118},[52,1351,136],{"class":66},[52,1353,1354,1356,1358,1360,1362,1364],{"class":54,"line":70},[52,1355,598],{"class":126},[52,1357,130],{"class":66},[52,1359,615],{"class":327},[52,1361,130],{"class":66},[52,1363,485],{"class":118},[52,1365,622],{"class":66},[52,1367,1368],{"class":54,"line":98},[52,1369,102],{"emptyLinePlaceholder":101},[52,1371,1372,1374,1376,1379],{"class":54,"line":105},[52,1373,585],{"class":111},[52,1375,588],{"class":348},[52,1377,1378],{"class":118}," my_function",[52,1380,593],{"class":66},[52,1382,1383,1385,1387,1389],{"class":54,"line":123},[52,1384,598],{"class":126},[52,1386,130],{"class":66},[52,1388,603],{"class":118},[52,1390,136],{"class":66},[52,1392,1393,1395,1397,1399,1401,1403],{"class":54,"line":608},[52,1394,598],{"class":126},[52,1396,130],{"class":66},[52,1398,615],{"class":327},[52,1400,130],{"class":66},[52,1402,603],{"class":118},[52,1404,622],{"class":66},[357,1406,1408],{"id":1407},"example","Example",[43,1410,1412],{"className":45,"code":1411,"language":47,"meta":48,"style":48},"def get_numbers():\n    return [1, 2, 3]\n\nprint(get_numbers)\nprint(type(get_numbers))\n\nvalue = get_numbers()\nprint(value)\nprint(type(value))\n",[15,1413,1414,1422,1440,1444,1454,1468,1472,1482,1493],{"__ignoreMap":48},[52,1415,1416,1418,1420],{"class":54,"line":55},[52,1417,59],{"class":58},[52,1419,63],{"class":62},[52,1421,67],{"class":66},[52,1423,1424,1426,1428,1430,1432,1434,1436,1438],{"class":54,"line":70},[52,1425,74],{"class":73},[52,1427,77],{"class":66},[52,1429,81],{"class":80},[52,1431,84],{"class":66},[52,1433,87],{"class":80},[52,1435,84],{"class":66},[52,1437,92],{"class":80},[52,1439,95],{"class":66},[52,1441,1442],{"class":54,"line":98},[52,1443,102],{"emptyLinePlaceholder":101},[52,1445,1446,1448,1450,1452],{"class":54,"line":105},[52,1447,598],{"class":126},[52,1449,130],{"class":66},[52,1451,367],{"class":118},[52,1453,136],{"class":66},[52,1455,1456,1458,1460,1462,1464,1466],{"class":54,"line":123},[52,1457,598],{"class":126},[52,1459,130],{"class":66},[52,1461,615],{"class":327},[52,1463,130],{"class":66},[52,1465,367],{"class":118},[52,1467,622],{"class":66},[52,1469,1470],{"class":54,"line":608},[52,1471,102],{"emptyLinePlaceholder":101},[52,1473,1474,1476,1478,1480],{"class":54,"line":825},[52,1475,585],{"class":111},[52,1477,588],{"class":348},[52,1479,63],{"class":118},[52,1481,593],{"class":66},[52,1483,1485,1487,1489,1491],{"class":54,"line":1484},8,[52,1486,598],{"class":126},[52,1488,130],{"class":66},[52,1490,603],{"class":118},[52,1492,136],{"class":66},[52,1494,1496,1498,1500,1502,1504,1506],{"class":54,"line":1495},9,[52,1497,598],{"class":126},[52,1499,130],{"class":66},[52,1501,615],{"class":327},[52,1503,130],{"class":66},[52,1505,603],{"class":118},[52,1507,622],{"class":66},[20,1509,317],{},[43,1511,1513],{"className":45,"code":1512,"language":47,"meta":48,"style":48},"\u003Cfunction get_numbers at 0x...>\n\u003Cclass 'function'>\n[1, 2, 3]\n\u003Cclass 'list'>\n",[15,1514,1515,1532,1546,1563],{"__ignoreMap":48},[52,1516,1517,1519,1522,1526,1530],{"class":54,"line":55},[52,1518,639],{"class":348},[52,1520,1521],{"class":111},"function get_numbers at ",[52,1523,1525],{"class":1524},"srjyR","0x",[52,1527,1529],{"class":1528},"s_hVV","...",[52,1531,652],{"class":348},[52,1533,1534,1536,1538,1540,1542,1544],{"class":54,"line":70},[52,1535,639],{"class":348},[52,1537,642],{"class":58},[52,1539,335],{"class":334},[52,1541,339],{"class":338},[52,1543,342],{"class":334},[52,1545,652],{"class":348},[52,1547,1548,1551,1553,1555,1557,1559,1561],{"class":54,"line":98},[52,1549,1550],{"class":66},"[",[52,1552,81],{"class":80},[52,1554,84],{"class":66},[52,1556,87],{"class":80},[52,1558,84],{"class":66},[52,1560,92],{"class":80},[52,1562,95],{"class":66},[52,1564,1565,1567,1569,1571,1573,1575],{"class":54,"line":105},[52,1566,639],{"class":348},[52,1568,642],{"class":58},[52,1570,335],{"class":334},[52,1572,1191],{"class":338},[52,1574,342],{"class":334},[52,1576,652],{"class":348},[20,1578,1579],{},"That makes the problem easier to spot:",[152,1581,1582,1587],{},[155,1583,1584,1586],{},[15,1585,367],{}," is a function",[155,1588,1589,1591],{},[15,1590,373],{}," is a list",[20,1593,1594,1595,36],{},"If you want a step-by-step process, see the ",[194,1596,1598],{"href":1597},"\u002Fhow-to\u002Fhow-to-debug-python-code-beginner-guide\u002F","beginner guide to debugging Python code",[38,1600,1602],{"id":1601},"common-mistakes","Common mistakes",[20,1604,1605],{},"These are the most common causes of this error:",[152,1607,1608,1618,1627,1632,1635],{},[155,1609,1610,1611,1614,1615],{},"Using ",[15,1612,1613],{},"for x in my_function"," instead of ",[15,1616,1617],{},"for x in my_function()",[155,1619,1620,1621,1623,1624,1626],{},"Passing a function to ",[15,1622,229],{}," or ",[15,1625,236],{}," by mistake",[155,1628,1629,1630,1081],{},"Forgetting to call a function before using the ",[15,1631,115],{},[155,1633,1634],{},"Returning a function object instead of returned data",[155,1636,1637],{},"Reusing the same name for both data and a function",[20,1639,1640],{},"Here is one more example of returning a function by mistake:",[43,1642,1644],{"className":45,"code":1643,"language":47,"meta":48,"style":48},"def get_numbers():\n    return [1, 2, 3]\n\ndef wrapper():\n    return get_numbers\n\nfor n in wrapper():\n    print(n)\n",[15,1645,1646,1654,1672,1676,1685,1692,1696,1708],{"__ignoreMap":48},[52,1647,1648,1650,1652],{"class":54,"line":55},[52,1649,59],{"class":58},[52,1651,63],{"class":62},[52,1653,67],{"class":66},[52,1655,1656,1658,1660,1662,1664,1666,1668,1670],{"class":54,"line":70},[52,1657,74],{"class":73},[52,1659,77],{"class":66},[52,1661,81],{"class":80},[52,1663,84],{"class":66},[52,1665,87],{"class":80},[52,1667,84],{"class":66},[52,1669,92],{"class":80},[52,1671,95],{"class":66},[52,1673,1674],{"class":54,"line":98},[52,1675,102],{"emptyLinePlaceholder":101},[52,1677,1678,1680,1683],{"class":54,"line":105},[52,1679,59],{"class":58},[52,1681,1682],{"class":62}," wrapper",[52,1684,67],{"class":66},[52,1686,1687,1689],{"class":54,"line":123},[52,1688,74],{"class":73},[52,1690,1691],{"class":111}," get_numbers\n",[52,1693,1694],{"class":54,"line":608},[52,1695,102],{"emptyLinePlaceholder":101},[52,1697,1698,1700,1702,1704,1706],{"class":54,"line":825},[52,1699,108],{"class":73},[52,1701,112],{"class":111},[52,1703,115],{"class":73},[52,1705,1682],{"class":118},[52,1707,67],{"class":66},[52,1709,1710,1712,1714,1716],{"class":54,"line":1484},[52,1711,127],{"class":126},[52,1713,130],{"class":66},[52,1715,133],{"class":118},[52,1717,136],{"class":66},[20,1719,837,1720,1723,1724,1726],{},[15,1721,1722],{},"wrapper()"," returns the function ",[15,1725,367],{},", not the list.",[357,1728,1730],{"id":1729},"correct-version","Correct version",[43,1732,1734],{"className":45,"code":1733,"language":47,"meta":48,"style":48},"def get_numbers():\n    return [1, 2, 3]\n\ndef wrapper():\n    return get_numbers()\n\nfor n in wrapper():\n    print(n)\n",[15,1735,1736,1744,1762,1766,1774,1782,1786,1798],{"__ignoreMap":48},[52,1737,1738,1740,1742],{"class":54,"line":55},[52,1739,59],{"class":58},[52,1741,63],{"class":62},[52,1743,67],{"class":66},[52,1745,1746,1748,1750,1752,1754,1756,1758,1760],{"class":54,"line":70},[52,1747,74],{"class":73},[52,1749,77],{"class":66},[52,1751,81],{"class":80},[52,1753,84],{"class":66},[52,1755,87],{"class":80},[52,1757,84],{"class":66},[52,1759,92],{"class":80},[52,1761,95],{"class":66},[52,1763,1764],{"class":54,"line":98},[52,1765,102],{"emptyLinePlaceholder":101},[52,1767,1768,1770,1772],{"class":54,"line":105},[52,1769,59],{"class":58},[52,1771,1682],{"class":62},[52,1773,67],{"class":66},[52,1775,1776,1778,1780],{"class":54,"line":123},[52,1777,74],{"class":73},[52,1779,63],{"class":118},[52,1781,593],{"class":66},[52,1783,1784],{"class":54,"line":608},[52,1785,102],{"emptyLinePlaceholder":101},[52,1787,1788,1790,1792,1794,1796],{"class":54,"line":825},[52,1789,108],{"class":73},[52,1791,112],{"class":111},[52,1793,115],{"class":73},[52,1795,1682],{"class":118},[52,1797,67],{"class":66},[52,1799,1800,1802,1804,1806],{"class":54,"line":1484},[52,1801,127],{"class":126},[52,1803,130],{"class":66},[52,1805,133],{"class":118},[52,1807,136],{"class":66},[38,1809,1811],{"id":1810},"faq","FAQ",[357,1813,1815],{"id":1814},"why-does-python-say-a-function-is-not-iterable","Why does Python say a function is not iterable?",[20,1817,1818],{},"Because a function is something you call with parentheses. It is not a collection of values you can loop over.",[357,1820,1822],{"id":1821},"how-do-i-fix-this-error-quickly","How do I fix this error quickly?",[20,1824,1825,1826,1828,1829,36],{},"Check whether you forgot parentheses. If you meant to use the function result, change ",[15,1827,485],{}," to ",[15,1830,479],{},[357,1832,1834],{"id":1833},"can-a-function-ever-be-iterable","Can a function ever be iterable?",[20,1836,1837],{},"Not by default. Normally you call a function to get a value, and then you iterate over that returned value if it is iterable.",[357,1839,1841],{"id":1840},"what-if-i-already-called-the-function-and-still-get-an-error","What if I already called the function and still get an error?",[20,1843,1844],{},"Then the returned value may not be iterable. Check the return value and its type.",[20,1846,1847,1848,1850,1851,1857,1858,198,1864,36],{},"If the returned value is ",[15,1849,658],{},", you may also want to read ",[194,1852,13,1854],{"href":1853},"\u002Ferrors\u002Ftypeerror-nonetype-object-is-not-iterable-fix\u002F",[15,1855,1856],{},"'NoneType' object is not iterable",". Similar problems can happen with ",[194,1859,13,1861],{"href":1860},"\u002Ferrors\u002Ftypeerror-int-object-is-not-iterable-fix\u002F",[15,1862,1863],{},"'int' object is not iterable",[194,1865,13,1867],{"href":1866},"\u002Ferrors\u002Ftypeerror-bool-object-is-not-iterable-fix\u002F",[15,1868,1869],{},"'bool' object is not iterable",[38,1871,1873],{"id":1872},"see-also","See also",[152,1875,1876,1880,1885,1892,1897,1903,1909],{},[155,1877,1878],{},[194,1879,197],{"href":196},[155,1881,1882],{},[194,1883,1884],{"href":201},"Iterators and iterable objects explained",[155,1886,1887],{},[194,1888,731,1889,1891],{"href":730},[15,1890,734],{}," function explained",[155,1893,1894],{},[194,1895,1896],{"href":1597},"Beginner guide to debugging Python code",[155,1898,1899],{},[194,1900,13,1901],{"href":1853},[15,1902,1856],{},[155,1904,1905],{},[194,1906,13,1907],{"href":1860},[15,1908,1863],{},[155,1910,1911],{},[194,1912,13,1913],{"href":1866},[15,1914,1869],{},[1916,1917,1918],"style",{},"html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--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 .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 .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .srjyR, html code.shiki .srjyR{--shiki-light:#90A4AE;--shiki-light-font-style:inherit;--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":48,"searchDepth":70,"depth":70,"links":1920},[1921,1922,1923,1924,1927,1928,1931,1934,1944,1947,1950,1956],{"id":40,"depth":70,"text":41},{"id":142,"depth":70,"text":143},{"id":205,"depth":70,"text":206},{"id":252,"depth":70,"text":253,"children":1925},[1926],{"id":359,"depth":98,"text":360},{"id":384,"depth":70,"text":385},{"id":489,"depth":70,"text":490,"children":1929},[1930],{"id":553,"depth":98,"text":554},{"id":738,"depth":70,"text":739,"children":1932},[1933],{"id":844,"depth":98,"text":845},{"id":996,"depth":70,"text":997,"children":1935},[1936,1938,1940,1942],{"id":1003,"depth":98,"text":1937},"In a for loop",{"id":1077,"depth":98,"text":1939},"With the in operator",{"id":1145,"depth":98,"text":1941},"With list(), tuple(), or set()",{"id":1201,"depth":98,"text":1943},"With sum()",{"id":1314,"depth":70,"text":1315,"children":1945},[1946],{"id":1407,"depth":98,"text":1408},{"id":1601,"depth":70,"text":1602,"children":1948},[1949],{"id":1729,"depth":98,"text":1730},{"id":1810,"depth":70,"text":1811,"children":1951},[1952,1953,1954,1955],{"id":1814,"depth":98,"text":1815},{"id":1821,"depth":98,"text":1822},{"id":1833,"depth":98,"text":1834},{"id":1840,"depth":98,"text":1841},{"id":1872,"depth":70,"text":1873},"Master typeerror function object is not iterable fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Ftypeerror-function-object-is-not-iterable-fix",{"title":5,"description":1957},"errors\u002Ftypeerror-function-object-is-not-iterable-fix","R3VHHeVM486hjj-mJ4qCvL8wW4X7C7vDCooXdNIeEwg",1777585481023]