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