[{"data":1,"prerenderedAt":2606},["ShallowReactive",2],{"doc-\u002Ferrors\u002Ftypeerror-nonetype-object-is-not-iterable-fix":3},{"id":4,"title":5,"body":6,"description":2599,"extension":2600,"meta":2601,"navigation":74,"path":2602,"seo":2603,"stem":2604,"__hash__":2605},"content\u002Ferrors\u002Ftypeerror-nonetype-object-is-not-iterable-fix.md","TypeError: 'NoneType' object is not iterable (Fix)",{"type":7,"value":8,"toc":2562},"minimark",[9,19,34,39,145,154,158,172,177,190,193,236,242,264,287,304,308,311,413,416,497,502,509,519,522,537,546,549,566,570,573,658,660,680,687,691,697,700,723,726,841,844,905,909,914,941,944,985,1035,1066,1096,1100,1166,1175,1239,1246,1250,1253,1284,1288,1367,1373,1430,1436,1440,1485,1491,1495,1600,1607,1612,1615,1652,1655,1744,1748,1851,1853,1922,1931,1938,1942,1947,1950,1972,1975,1979,2046,2060,2064,2125,2127,2147,2152,2235,2238,2312,2319,2323,2326,2329,2346,2349,2352,2372,2378,2403,2406,2409,2414,2417,2424,2428,2431,2466,2470,2474,2485,2489,2495,2499,2505,2509,2512,2516,2533,2537,2558],[10,11,13,14,18],"h1",{"id":12},"typeerror-nonetype-object-is-not-iterable-fix","TypeError: ",[15,16,17],"code",{},"'NoneType' object is not iterable"," (Fix)",[20,21,22,23,29,30,33],"p",{},"Fix the Python error ",[24,25,26],"strong",{},[15,27,28],{},"TypeError: 'NoneType' object is not iterable",". This page explains what it means, why it happens, how to find where ",[15,31,32],{},"None"," came from, and simple ways to fix it.",[35,36,38],"h2",{"id":37},"quick-fix","Quick fix",[40,41,46],"pre",{"className":42,"code":43,"language":44,"meta":45,"style":45},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","items = get_items()\n\nif items is None:\n    items = []\n\nfor item in items:\n    print(item)\n","python","",[15,47,48,69,76,96,107,112,129],{"__ignoreMap":45},[49,50,53,57,61,65],"span",{"class":51,"line":52},"line",1,[49,54,56],{"class":55},"su5hD","items ",[49,58,60],{"class":59},"smGrS","=",[49,62,64],{"class":63},"slqww"," get_items",[49,66,68],{"class":67},"sP7_E","()\n",[49,70,72],{"class":51,"line":71},2,[49,73,75],{"emptyLinePlaceholder":74},true,"\n",[49,77,79,83,86,89,93],{"class":51,"line":78},3,[49,80,82],{"class":81},"sVHd0","if",[49,84,85],{"class":55}," items ",[49,87,88],{"class":59},"is",[49,90,92],{"class":91},"s39Yj"," None",[49,94,95],{"class":67},":\n",[49,97,99,102,104],{"class":51,"line":98},4,[49,100,101],{"class":55},"    items ",[49,103,60],{"class":59},[49,105,106],{"class":67}," []\n",[49,108,110],{"class":51,"line":109},5,[49,111,75],{"emptyLinePlaceholder":74},[49,113,115,118,121,124,127],{"class":51,"line":114},6,[49,116,117],{"class":81},"for",[49,119,120],{"class":55}," item ",[49,122,123],{"class":81},"in",[49,125,126],{"class":55}," items",[49,128,95],{"class":67},[49,130,132,136,139,142],{"class":51,"line":131},7,[49,133,135],{"class":134},"sptTA","    print",[49,137,138],{"class":67},"(",[49,140,141],{"class":63},"item",[49,143,144],{"class":67},")\n",[20,146,147,148,153],{},"Use this only when an empty list makes sense. The real fix is to find out ",[24,149,150,151],{},"why the value is ",[15,152,32],{},".",[35,155,157],{"id":156},"what-this-error-means","What this error means",[20,159,160,161,164,165,168,169,171],{},"This error happens when Python expects something it can ",[24,162,163],{},"loop over"," or ",[24,166,167],{},"check membership in",", but it gets ",[15,170,32],{}," instead.",[20,173,174,176],{},[15,175,32],{}," means:",[178,179,180,184,187],"ul",{},[181,182,183],"li",{},"no value",[181,185,186],{},"nothing was returned",[181,188,189],{},"the value is missing",[20,191,192],{},"This often happens in places like:",[178,194,195,200,205,210,215,220,225,230],{},[181,196,197,199],{},[15,198,117],{}," loops",[181,201,202],{},[15,203,204],{},"list()",[181,206,207],{},[15,208,209],{},"tuple()",[181,211,212],{},[15,213,214],{},"set()",[181,216,217],{},[15,218,219],{},"sum()",[181,221,222],{},[15,223,224],{},"any()",[181,226,227],{},[15,228,229],{},"all()",[181,231,232,233,235],{},"the ",[15,234,123],{}," operator",[20,237,238,239,241],{},"For example, all of these can fail if the value is ",[15,240,32],{},":",[40,243,245],{"className":42,"code":244,"language":44,"meta":45,"style":45},"for item in None:\n    pass\n",[15,246,247,259],{"__ignoreMap":45},[49,248,249,251,253,255,257],{"class":51,"line":52},[49,250,117],{"class":81},[49,252,120],{"class":55},[49,254,123],{"class":81},[49,256,92],{"class":91},[49,258,95],{"class":67},[49,260,261],{"class":51,"line":71},[49,262,263],{"class":81},"    pass\n",[40,265,267],{"className":42,"code":266,"language":44,"meta":45,"style":45},"'a' in None\n",[15,268,269],{"__ignoreMap":45},[49,270,271,275,279,281,284],{"class":51,"line":52},[49,272,274],{"class":273},"s2W-s","'",[49,276,278],{"class":277},"sithA","a",[49,280,274],{"class":273},[49,282,283],{"class":59}," in",[49,285,286],{"class":91}," None\n",[40,288,290],{"className":42,"code":289,"language":44,"meta":45,"style":45},"list(None)\n",[15,291,292],{"__ignoreMap":45},[49,293,294,298,300,302],{"class":51,"line":52},[49,295,297],{"class":296},"sZMiF","list",[49,299,138],{"class":67},[49,301,32],{"class":91},[49,303,144],{"class":67},[35,305,307],{"id":306},"a-simple-example-that-causes-the-error","A simple example that causes the error",[20,309,310],{},"A very common cause is a function that prints something but does not return anything.",[40,312,314],{"className":42,"code":313,"language":44,"meta":45,"style":45},"def get_names():\n    print([\"Ana\", \"Ben\", \"Cara\"])\n\nnames = get_names()\n\nfor name in names:\n    print(name)\n",[15,315,316,329,369,373,384,388,402],{"__ignoreMap":45},[49,317,318,322,326],{"class":51,"line":52},[49,319,321],{"class":320},"sbsja","def",[49,323,325],{"class":324},"sGLFI"," get_names",[49,327,328],{"class":67},"():\n",[49,330,331,333,336,340,344,346,349,352,355,357,359,361,364,366],{"class":51,"line":71},[49,332,135],{"class":134},[49,334,335],{"class":67},"([",[49,337,339],{"class":338},"sjJ54","\"",[49,341,343],{"class":342},"s_sjI","Ana",[49,345,339],{"class":338},[49,347,348],{"class":67},",",[49,350,351],{"class":338}," \"",[49,353,354],{"class":342},"Ben",[49,356,339],{"class":338},[49,358,348],{"class":67},[49,360,351],{"class":338},[49,362,363],{"class":342},"Cara",[49,365,339],{"class":338},[49,367,368],{"class":67},"])\n",[49,370,371],{"class":51,"line":78},[49,372,75],{"emptyLinePlaceholder":74},[49,374,375,378,380,382],{"class":51,"line":98},[49,376,377],{"class":55},"names ",[49,379,60],{"class":59},[49,381,325],{"class":63},[49,383,68],{"class":67},[49,385,386],{"class":51,"line":109},[49,387,75],{"emptyLinePlaceholder":74},[49,389,390,392,395,397,400],{"class":51,"line":114},[49,391,117],{"class":81},[49,393,394],{"class":55}," name ",[49,396,123],{"class":81},[49,398,399],{"class":55}," names",[49,401,95],{"class":67},[49,403,404,406,408,411],{"class":51,"line":131},[49,405,135],{"class":134},[49,407,138],{"class":67},[49,409,410],{"class":63},"name",[49,412,144],{"class":67},[20,414,415],{},"Output:",[40,417,419],{"className":42,"code":418,"language":44,"meta":45,"style":45},"['Ana', 'Ben', 'Cara']\nTraceback (most recent call last):\n  ...\nTypeError: 'NoneType' object is not iterable\n",[15,420,421,452,465,471],{"__ignoreMap":45},[49,422,423,426,428,430,432,434,437,439,441,443,445,447,449],{"class":51,"line":52},[49,424,425],{"class":67},"[",[49,427,274],{"class":338},[49,429,343],{"class":342},[49,431,274],{"class":338},[49,433,348],{"class":67},[49,435,436],{"class":338}," '",[49,438,354],{"class":342},[49,440,274],{"class":338},[49,442,348],{"class":67},[49,444,436],{"class":338},[49,446,363],{"class":342},[49,448,274],{"class":338},[49,450,451],{"class":67},"]\n",[49,453,454,457,459,462],{"class":51,"line":71},[49,455,456],{"class":63},"Traceback ",[49,458,138],{"class":67},[49,460,461],{"class":63},"most recent call last",[49,463,464],{"class":67},"):\n",[49,466,467],{"class":51,"line":78},[49,468,470],{"class":469},"s_hVV","  ...\n",[49,472,473,476,478,480,483,485,488,491,494],{"class":51,"line":98},[49,474,475],{"class":296},"TypeError",[49,477,241],{"class":67},[49,479,436],{"class":338},[49,481,482],{"class":342},"NoneType",[49,484,274],{"class":338},[49,486,487],{"class":296}," object",[49,489,490],{"class":59}," is",[49,492,493],{"class":59}," not",[49,495,496],{"class":55}," iterable\n",[498,499,501],"h3",{"id":500},"why-this-happens","Why this happens",[20,503,504,505,508],{},"The function prints a list, but it does ",[24,506,507],{},"not"," return one.",[20,510,511,512,515,516,518],{},"In Python, if a function has no ",[15,513,514],{},"return"," statement, it returns ",[15,517,32],{}," by default.",[20,520,521],{},"So this line:",[40,523,525],{"className":42,"code":524,"language":44,"meta":45,"style":45},"names = get_names()\n",[15,526,527],{"__ignoreMap":45},[49,528,529,531,533,535],{"class":51,"line":52},[49,530,377],{"class":55},[49,532,60],{"class":59},[49,534,325],{"class":63},[49,536,68],{"class":67},[20,538,539,540,542,543,153],{},"stores ",[15,541,32],{}," in ",[15,544,545],{},"names",[20,547,548],{},"Then this line fails:",[40,550,552],{"className":42,"code":551,"language":44,"meta":45,"style":45},"for name in names:\n",[15,553,554],{"__ignoreMap":45},[49,555,556,558,560,562,564],{"class":51,"line":52},[49,557,117],{"class":81},[49,559,394],{"class":55},[49,561,123],{"class":81},[49,563,399],{"class":55},[49,565,95],{"class":67},[498,567,569],{"id":568},"the-fix","The fix",[20,571,572],{},"Return the list from the function:",[40,574,576],{"className":42,"code":575,"language":44,"meta":45,"style":45},"def get_names():\n    return [\"Ana\", \"Ben\", \"Cara\"]\n\nnames = get_names()\n\nfor name in names:\n    print(name)\n",[15,577,578,586,618,622,632,636,648],{"__ignoreMap":45},[49,579,580,582,584],{"class":51,"line":52},[49,581,321],{"class":320},[49,583,325],{"class":324},[49,585,328],{"class":67},[49,587,588,591,594,596,598,600,602,604,606,608,610,612,614,616],{"class":51,"line":71},[49,589,590],{"class":81},"    return",[49,592,593],{"class":67}," [",[49,595,339],{"class":338},[49,597,343],{"class":342},[49,599,339],{"class":338},[49,601,348],{"class":67},[49,603,351],{"class":338},[49,605,354],{"class":342},[49,607,339],{"class":338},[49,609,348],{"class":67},[49,611,351],{"class":338},[49,613,363],{"class":342},[49,615,339],{"class":338},[49,617,451],{"class":67},[49,619,620],{"class":51,"line":78},[49,621,75],{"emptyLinePlaceholder":74},[49,623,624,626,628,630],{"class":51,"line":98},[49,625,377],{"class":55},[49,627,60],{"class":59},[49,629,325],{"class":63},[49,631,68],{"class":67},[49,633,634],{"class":51,"line":109},[49,635,75],{"emptyLinePlaceholder":74},[49,637,638,640,642,644,646],{"class":51,"line":114},[49,639,117],{"class":81},[49,641,394],{"class":55},[49,643,123],{"class":81},[49,645,399],{"class":55},[49,647,95],{"class":67},[49,649,650,652,654,656],{"class":51,"line":131},[49,651,135],{"class":134},[49,653,138],{"class":67},[49,655,410],{"class":63},[49,657,144],{"class":67},[20,659,415],{},[40,661,663],{"className":42,"code":662,"language":44,"meta":45,"style":45},"Ana\nBen\nCara\n",[15,664,665,670,675],{"__ignoreMap":45},[49,666,667],{"class":51,"line":52},[49,668,669],{"class":55},"Ana\n",[49,671,672],{"class":51,"line":71},[49,673,674],{"class":55},"Ben\n",[49,676,677],{"class":51,"line":78},[49,678,679],{"class":55},"Cara\n",[20,681,682,683,153],{},"If function return values are confusing, see ",[278,684,686],{"href":685},"\u002Flearn\u002Freturn-values-in-python-functions\u002F","return values in Python functions",[35,688,690],{"id":689},"why-it-happens","Why it happens",[20,692,693,694,696],{},"This error usually means ",[15,695,32],{}," appeared earlier in your code.",[20,698,699],{},"Common reasons include:",[178,701,702,705,711,714,717],{},[181,703,704],{},"A function forgot to return a value.",[181,706,707,708,710],{},"A variable was set to ",[15,709,32],{}," earlier in the program.",[181,712,713],{},"A method was used incorrectly and its return value was assigned.",[181,715,716],{},"Data was missing from a file, API, or dictionary lookup.",[181,718,719,720,722],{},"One branch of an ",[15,721,82],{}," statement returns a list, but another branch returns nothing.",[20,724,725],{},"Here is an example of inconsistent returns:",[40,727,729],{"className":42,"code":728,"language":44,"meta":45,"style":45},"def get_items(include):\n    if include:\n        return [\"a\", \"b\", \"c\"]\n    # no return here\n\nitems = get_items(False)\n\nfor item in items:\n    print(item)\n",[15,730,731,745,755,788,794,798,813,817,830],{"__ignoreMap":45},[49,732,733,735,737,739,743],{"class":51,"line":52},[49,734,321],{"class":320},[49,736,64],{"class":324},[49,738,138],{"class":67},[49,740,742],{"class":741},"sFwrP","include",[49,744,464],{"class":67},[49,746,747,750,753],{"class":51,"line":71},[49,748,749],{"class":81},"    if",[49,751,752],{"class":55}," include",[49,754,95],{"class":67},[49,756,757,760,762,764,766,768,770,772,775,777,779,781,784,786],{"class":51,"line":78},[49,758,759],{"class":81},"        return",[49,761,593],{"class":67},[49,763,339],{"class":338},[49,765,278],{"class":342},[49,767,339],{"class":338},[49,769,348],{"class":67},[49,771,351],{"class":338},[49,773,774],{"class":342},"b",[49,776,339],{"class":338},[49,778,348],{"class":67},[49,780,351],{"class":338},[49,782,783],{"class":342},"c",[49,785,339],{"class":338},[49,787,451],{"class":67},[49,789,790],{"class":51,"line":98},[49,791,793],{"class":792},"sutJx","    # no return here\n",[49,795,796],{"class":51,"line":109},[49,797,75],{"emptyLinePlaceholder":74},[49,799,800,802,804,806,808,811],{"class":51,"line":114},[49,801,56],{"class":55},[49,803,60],{"class":59},[49,805,64],{"class":63},[49,807,138],{"class":67},[49,809,810],{"class":91},"False",[49,812,144],{"class":67},[49,814,815],{"class":51,"line":131},[49,816,75],{"emptyLinePlaceholder":74},[49,818,820,822,824,826,828],{"class":51,"line":819},8,[49,821,117],{"class":81},[49,823,120],{"class":55},[49,825,123],{"class":81},[49,827,126],{"class":55},[49,829,95],{"class":67},[49,831,833,835,837,839],{"class":51,"line":832},9,[49,834,135],{"class":134},[49,836,138],{"class":67},[49,838,141],{"class":63},[49,840,144],{"class":67},[20,842,843],{},"The fix is to make every branch return the same kind of value:",[40,845,847],{"className":42,"code":846,"language":44,"meta":45,"style":45},"def get_items(include):\n    if include:\n        return [\"a\", \"b\", \"c\"]\n    return []\n",[15,848,849,861,869,899],{"__ignoreMap":45},[49,850,851,853,855,857,859],{"class":51,"line":52},[49,852,321],{"class":320},[49,854,64],{"class":324},[49,856,138],{"class":67},[49,858,742],{"class":741},[49,860,464],{"class":67},[49,862,863,865,867],{"class":51,"line":71},[49,864,749],{"class":81},[49,866,752],{"class":55},[49,868,95],{"class":67},[49,870,871,873,875,877,879,881,883,885,887,889,891,893,895,897],{"class":51,"line":78},[49,872,759],{"class":81},[49,874,593],{"class":67},[49,876,339],{"class":338},[49,878,278],{"class":342},[49,880,339],{"class":338},[49,882,348],{"class":67},[49,884,351],{"class":338},[49,886,774],{"class":342},[49,888,339],{"class":338},[49,890,348],{"class":67},[49,892,351],{"class":338},[49,894,783],{"class":342},[49,896,339],{"class":338},[49,898,451],{"class":67},[49,900,901,903],{"class":51,"line":98},[49,902,590],{"class":81},[49,904,106],{"class":67},[35,906,908],{"id":907},"common-code-patterns-that-produce-this-error","Common code patterns that produce this error",[20,910,911,912,241],{},"These patterns often lead to this error when the value is ",[15,913,32],{},[178,915,916,921,926,931,936],{},[181,917,918],{},[15,919,920],{},"for item in result",[181,922,923],{},[15,924,925],{},"if 'a' in text",[181,927,928],{},[15,929,930],{},"list(value)",[181,932,933],{},[15,934,935],{},"sum(numbers)",[181,937,938],{},[15,939,940],{},"for key in data.get('items')",[20,942,943],{},"Examples:",[40,945,947],{"className":42,"code":946,"language":44,"meta":45,"style":45},"result = None\n\nfor item in result:\n    print(item)\n",[15,948,949,958,962,975],{"__ignoreMap":45},[49,950,951,954,956],{"class":51,"line":52},[49,952,953],{"class":55},"result ",[49,955,60],{"class":59},[49,957,286],{"class":91},[49,959,960],{"class":51,"line":71},[49,961,75],{"emptyLinePlaceholder":74},[49,963,964,966,968,970,973],{"class":51,"line":78},[49,965,117],{"class":81},[49,967,120],{"class":55},[49,969,123],{"class":81},[49,971,972],{"class":55}," result",[49,974,95],{"class":67},[49,976,977,979,981,983],{"class":51,"line":98},[49,978,135],{"class":134},[49,980,138],{"class":67},[49,982,141],{"class":63},[49,984,144],{"class":67},[40,986,988],{"className":42,"code":987,"language":44,"meta":45,"style":45},"text = None\n\nif \"a\" in text:\n    print(\"found\")\n",[15,989,990,999,1003,1020],{"__ignoreMap":45},[49,991,992,995,997],{"class":51,"line":52},[49,993,994],{"class":55},"text ",[49,996,60],{"class":59},[49,998,286],{"class":91},[49,1000,1001],{"class":51,"line":71},[49,1002,75],{"emptyLinePlaceholder":74},[49,1004,1005,1007,1009,1011,1013,1015,1018],{"class":51,"line":78},[49,1006,82],{"class":81},[49,1008,351],{"class":338},[49,1010,278],{"class":342},[49,1012,339],{"class":338},[49,1014,283],{"class":59},[49,1016,1017],{"class":55}," text",[49,1019,95],{"class":67},[49,1021,1022,1024,1026,1028,1031,1033],{"class":51,"line":98},[49,1023,135],{"class":134},[49,1025,138],{"class":67},[49,1027,339],{"class":338},[49,1029,1030],{"class":342},"found",[49,1032,339],{"class":338},[49,1034,144],{"class":67},[40,1036,1038],{"className":42,"code":1037,"language":44,"meta":45,"style":45},"value = None\nprint(list(value))\n",[15,1039,1040,1049],{"__ignoreMap":45},[49,1041,1042,1045,1047],{"class":51,"line":52},[49,1043,1044],{"class":55},"value ",[49,1046,60],{"class":59},[49,1048,286],{"class":91},[49,1050,1051,1054,1056,1058,1060,1063],{"class":51,"line":71},[49,1052,1053],{"class":134},"print",[49,1055,138],{"class":67},[49,1057,297],{"class":296},[49,1059,138],{"class":67},[49,1061,1062],{"class":63},"value",[49,1064,1065],{"class":67},"))\n",[40,1067,1069],{"className":42,"code":1068,"language":44,"meta":45,"style":45},"numbers = None\nprint(sum(numbers))\n",[15,1070,1071,1080],{"__ignoreMap":45},[49,1072,1073,1076,1078],{"class":51,"line":52},[49,1074,1075],{"class":55},"numbers ",[49,1077,60],{"class":59},[49,1079,286],{"class":91},[49,1081,1082,1084,1086,1089,1091,1094],{"class":51,"line":71},[49,1083,1053],{"class":134},[49,1085,138],{"class":67},[49,1087,1088],{"class":134},"sum",[49,1090,138],{"class":67},[49,1092,1093],{"class":63},"numbers",[49,1095,1065],{"class":67},[498,1097,1099],{"id":1098},"missing-dictionary-key-example","Missing dictionary key example",[40,1101,1103],{"className":42,"code":1102,"language":44,"meta":45,"style":45},"data = {}\nitems = data.get(\"items\")\n\nfor item in items:\n    print(item)\n",[15,1104,1105,1115,1140,1144,1156],{"__ignoreMap":45},[49,1106,1107,1110,1112],{"class":51,"line":52},[49,1108,1109],{"class":55},"data ",[49,1111,60],{"class":59},[49,1113,1114],{"class":67}," {}\n",[49,1116,1117,1119,1121,1124,1126,1129,1131,1133,1136,1138],{"class":51,"line":71},[49,1118,56],{"class":55},[49,1120,60],{"class":59},[49,1122,1123],{"class":55}," data",[49,1125,153],{"class":67},[49,1127,1128],{"class":63},"get",[49,1130,138],{"class":67},[49,1132,339],{"class":338},[49,1134,1135],{"class":342},"items",[49,1137,339],{"class":338},[49,1139,144],{"class":67},[49,1141,1142],{"class":51,"line":78},[49,1143,75],{"emptyLinePlaceholder":74},[49,1145,1146,1148,1150,1152,1154],{"class":51,"line":98},[49,1147,117],{"class":81},[49,1149,120],{"class":55},[49,1151,123],{"class":81},[49,1153,126],{"class":55},[49,1155,95],{"class":67},[49,1157,1158,1160,1162,1164],{"class":51,"line":109},[49,1159,135],{"class":134},[49,1161,138],{"class":67},[49,1163,141],{"class":63},[49,1165,144],{"class":67},[20,1167,1168,1171,1172,1174],{},[15,1169,1170],{},"dict.get()"," returns ",[15,1173,32],{}," by default when the key is missing. If you want a safe fallback, you can pass a default value:",[40,1176,1178],{"className":42,"code":1177,"language":44,"meta":45,"style":45},"data = {}\nitems = data.get(\"items\", [])\n\nfor item in items:\n    print(item)\n",[15,1179,1180,1188,1213,1217,1229],{"__ignoreMap":45},[49,1181,1182,1184,1186],{"class":51,"line":52},[49,1183,1109],{"class":55},[49,1185,60],{"class":59},[49,1187,1114],{"class":67},[49,1189,1190,1192,1194,1196,1198,1200,1202,1204,1206,1208,1210],{"class":51,"line":71},[49,1191,56],{"class":55},[49,1193,60],{"class":59},[49,1195,1123],{"class":55},[49,1197,153],{"class":67},[49,1199,1128],{"class":63},[49,1201,138],{"class":67},[49,1203,339],{"class":338},[49,1205,1135],{"class":342},[49,1207,339],{"class":338},[49,1209,348],{"class":67},[49,1211,1212],{"class":67}," [])\n",[49,1214,1215],{"class":51,"line":78},[49,1216,75],{"emptyLinePlaceholder":74},[49,1218,1219,1221,1223,1225,1227],{"class":51,"line":98},[49,1220,117],{"class":81},[49,1222,120],{"class":55},[49,1224,123],{"class":81},[49,1226,126],{"class":55},[49,1228,95],{"class":67},[49,1230,1231,1233,1235,1237],{"class":51,"line":109},[49,1232,135],{"class":134},[49,1234,138],{"class":67},[49,1236,141],{"class":63},[49,1238,144],{"class":67},[20,1240,1241,1242,153],{},"To learn more, see the ",[278,1243,1245],{"href":1244},"\u002Freference\u002Fpython-dictionary-get-method\u002F","Python dictionary get() method",[35,1247,1249],{"id":1248},"how-to-fix-it","How to fix it",[20,1251,1252],{},"Here are the main ways to fix this error:",[178,1254,1255,1261,1269,1276,1279],{},[181,1256,1257,1258,1260],{},"Add a ",[15,1259,514],{}," statement to the function that should return a list or other iterable.",[181,1262,1263,1264,1266,1267,153],{},"Check for ",[15,1265,32],{}," before looping or using ",[15,1268,123],{},[181,1270,1271,1272,1275],{},"Provide a safe default like ",[15,1273,1274],{},"[]"," when that matches your program logic.",[181,1277,1278],{},"Make sure every branch of a function returns the same kind of value.",[181,1280,1281,1282,153],{},"Trace the variable backward to where it first became ",[15,1283,32],{},[498,1285,1287],{"id":1286},"fix-1-return-a-real-value","Fix 1: Return a real value",[40,1289,1291],{"className":42,"code":1290,"language":44,"meta":45,"style":45},"def load_numbers():\n    return [1, 2, 3]\n\nnumbers = load_numbers()\n\nfor number in numbers:\n    print(number)\n",[15,1292,1293,1302,1324,1328,1338,1342,1356],{"__ignoreMap":45},[49,1294,1295,1297,1300],{"class":51,"line":52},[49,1296,321],{"class":320},[49,1298,1299],{"class":324}," load_numbers",[49,1301,328],{"class":67},[49,1303,1304,1306,1308,1312,1314,1317,1319,1322],{"class":51,"line":71},[49,1305,590],{"class":81},[49,1307,593],{"class":67},[49,1309,1311],{"class":1310},"srdBf","1",[49,1313,348],{"class":67},[49,1315,1316],{"class":1310}," 2",[49,1318,348],{"class":67},[49,1320,1321],{"class":1310}," 3",[49,1323,451],{"class":67},[49,1325,1326],{"class":51,"line":78},[49,1327,75],{"emptyLinePlaceholder":74},[49,1329,1330,1332,1334,1336],{"class":51,"line":98},[49,1331,1075],{"class":55},[49,1333,60],{"class":59},[49,1335,1299],{"class":63},[49,1337,68],{"class":67},[49,1339,1340],{"class":51,"line":109},[49,1341,75],{"emptyLinePlaceholder":74},[49,1343,1344,1346,1349,1351,1354],{"class":51,"line":114},[49,1345,117],{"class":81},[49,1347,1348],{"class":55}," number ",[49,1350,123],{"class":81},[49,1352,1353],{"class":55}," numbers",[49,1355,95],{"class":67},[49,1357,1358,1360,1362,1365],{"class":51,"line":131},[49,1359,135],{"class":134},[49,1361,138],{"class":67},[49,1363,1364],{"class":63},"number",[49,1366,144],{"class":67},[498,1368,1370,1371],{"id":1369},"fix-2-check-for-none","Fix 2: Check for ",[15,1372,32],{},[40,1374,1376],{"className":42,"code":1375,"language":44,"meta":45,"style":45},"items = get_items()\n\nif items is not None:\n    for item in items:\n        print(item)\n",[15,1377,1378,1388,1392,1406,1419],{"__ignoreMap":45},[49,1379,1380,1382,1384,1386],{"class":51,"line":52},[49,1381,56],{"class":55},[49,1383,60],{"class":59},[49,1385,64],{"class":63},[49,1387,68],{"class":67},[49,1389,1390],{"class":51,"line":71},[49,1391,75],{"emptyLinePlaceholder":74},[49,1393,1394,1396,1398,1400,1402,1404],{"class":51,"line":78},[49,1395,82],{"class":81},[49,1397,85],{"class":55},[49,1399,88],{"class":59},[49,1401,493],{"class":59},[49,1403,92],{"class":91},[49,1405,95],{"class":67},[49,1407,1408,1411,1413,1415,1417],{"class":51,"line":98},[49,1409,1410],{"class":81},"    for",[49,1412,120],{"class":55},[49,1414,123],{"class":81},[49,1416,126],{"class":55},[49,1418,95],{"class":67},[49,1420,1421,1424,1426,1428],{"class":51,"line":109},[49,1422,1423],{"class":134},"        print",[49,1425,138],{"class":67},[49,1427,141],{"class":63},[49,1429,144],{"class":67},[20,1431,1432,1433,1435],{},"This is a good choice when ",[15,1434,32],{}," has a special meaning, such as “data not available”.",[498,1437,1439],{"id":1438},"fix-3-use-a-default-value","Fix 3: Use a default value",[40,1441,1443],{"className":42,"code":1442,"language":44,"meta":45,"style":45},"items = get_items()\n\nfor item in items or []:\n    print(item)\n",[15,1444,1445,1455,1459,1475],{"__ignoreMap":45},[49,1446,1447,1449,1451,1453],{"class":51,"line":52},[49,1448,56],{"class":55},[49,1450,60],{"class":59},[49,1452,64],{"class":63},[49,1454,68],{"class":67},[49,1456,1457],{"class":51,"line":71},[49,1458,75],{"emptyLinePlaceholder":74},[49,1460,1461,1463,1465,1467,1469,1472],{"class":51,"line":78},[49,1462,117],{"class":81},[49,1464,120],{"class":55},[49,1466,123],{"class":81},[49,1468,85],{"class":55},[49,1470,1471],{"class":59},"or",[49,1473,1474],{"class":67}," []:\n",[49,1476,1477,1479,1481,1483],{"class":51,"line":98},[49,1478,135],{"class":134},[49,1480,138],{"class":67},[49,1482,141],{"class":63},[49,1484,144],{"class":67},[20,1486,1487,1488,1490],{},"This works when ",[15,1489,32],{}," and an empty list should be treated the same way.",[498,1492,1494],{"id":1493},"fix-4-make-all-branches-return-a-value","Fix 4: Make all branches return a value",[40,1496,1498],{"className":42,"code":1497,"language":44,"meta":45,"style":45},"def find_even_numbers(numbers):\n    if numbers is None:\n        return []\n\n    result = []\n    for number in numbers:\n        if number % 2 == 0:\n            result.append(number)\n    return result\n",[15,1499,1500,1513,1526,1532,1536,1545,1557,1577,1593],{"__ignoreMap":45},[49,1501,1502,1504,1507,1509,1511],{"class":51,"line":52},[49,1503,321],{"class":320},[49,1505,1506],{"class":324}," find_even_numbers",[49,1508,138],{"class":67},[49,1510,1093],{"class":741},[49,1512,464],{"class":67},[49,1514,1515,1517,1520,1522,1524],{"class":51,"line":71},[49,1516,749],{"class":81},[49,1518,1519],{"class":55}," numbers ",[49,1521,88],{"class":59},[49,1523,92],{"class":91},[49,1525,95],{"class":67},[49,1527,1528,1530],{"class":51,"line":78},[49,1529,759],{"class":81},[49,1531,106],{"class":67},[49,1533,1534],{"class":51,"line":98},[49,1535,75],{"emptyLinePlaceholder":74},[49,1537,1538,1541,1543],{"class":51,"line":109},[49,1539,1540],{"class":55},"    result ",[49,1542,60],{"class":59},[49,1544,106],{"class":67},[49,1546,1547,1549,1551,1553,1555],{"class":51,"line":114},[49,1548,1410],{"class":81},[49,1550,1348],{"class":55},[49,1552,123],{"class":81},[49,1554,1353],{"class":55},[49,1556,95],{"class":67},[49,1558,1559,1562,1564,1567,1569,1572,1575],{"class":51,"line":131},[49,1560,1561],{"class":81},"        if",[49,1563,1348],{"class":55},[49,1565,1566],{"class":59},"%",[49,1568,1316],{"class":1310},[49,1570,1571],{"class":59}," ==",[49,1573,1574],{"class":1310}," 0",[49,1576,95],{"class":67},[49,1578,1579,1582,1584,1587,1589,1591],{"class":51,"line":819},[49,1580,1581],{"class":55},"            result",[49,1583,153],{"class":67},[49,1585,1586],{"class":63},"append",[49,1588,138],{"class":67},[49,1590,1364],{"class":63},[49,1592,144],{"class":67},[49,1594,1595,1597],{"class":51,"line":832},[49,1596,590],{"class":81},[49,1598,1599],{"class":55}," result\n",[35,1601,1603,1604,1606],{"id":1602},"how-to-debug-where-none-came-from","How to debug where ",[15,1605,32],{}," came from",[20,1608,1609,1610,153],{},"The fastest fix is usually to find the exact line where the value became ",[15,1611,32],{},[20,1613,1614],{},"Try these steps:",[178,1616,1617,1620,1629,1632,1639],{},[181,1618,1619],{},"Print the variable right before the failing line.",[181,1621,1622,1623,1626,1627,153],{},"Print ",[15,1624,1625],{},"type(variable)"," to confirm it is ",[15,1628,482],{},[181,1630,1631],{},"Check function return values step by step.",[181,1633,1634,1635,1638],{},"Look for assignments like ",[15,1636,1637],{},"value = some_method()"," where the method changes data in place.",[181,1640,1641,1642,1644,1645,1648,1649,1651],{},"Review ",[15,1643,82],{},"\u002F",[15,1646,1647],{},"else"," branches for missing ",[15,1650,514],{}," statements.",[20,1653,1654],{},"Useful debugging commands:",[40,1656,1658],{"className":42,"code":1657,"language":44,"meta":45,"style":45},"print(items)\nprint(type(items))\nprint(result is None)\nprint(my_function())\nhelp(list.sort)\nhelp(dict.update)\n",[15,1659,1660,1670,1685,1699,1711,1728],{"__ignoreMap":45},[49,1661,1662,1664,1666,1668],{"class":51,"line":52},[49,1663,1053],{"class":134},[49,1665,138],{"class":67},[49,1667,1135],{"class":63},[49,1669,144],{"class":67},[49,1671,1672,1674,1676,1679,1681,1683],{"class":51,"line":71},[49,1673,1053],{"class":134},[49,1675,138],{"class":67},[49,1677,1678],{"class":296},"type",[49,1680,138],{"class":67},[49,1682,1135],{"class":63},[49,1684,1065],{"class":67},[49,1686,1687,1689,1691,1693,1695,1697],{"class":51,"line":78},[49,1688,1053],{"class":134},[49,1690,138],{"class":67},[49,1692,953],{"class":63},[49,1694,88],{"class":81},[49,1696,92],{"class":91},[49,1698,144],{"class":67},[49,1700,1701,1703,1705,1708],{"class":51,"line":98},[49,1702,1053],{"class":134},[49,1704,138],{"class":67},[49,1706,1707],{"class":63},"my_function",[49,1709,1710],{"class":67},"())\n",[49,1712,1713,1716,1718,1720,1722,1726],{"class":51,"line":109},[49,1714,1715],{"class":134},"help",[49,1717,138],{"class":67},[49,1719,297],{"class":296},[49,1721,153],{"class":67},[49,1723,1725],{"class":1724},"skxfh","sort",[49,1727,144],{"class":67},[49,1729,1730,1732,1734,1737,1739,1742],{"class":51,"line":114},[49,1731,1715],{"class":134},[49,1733,138],{"class":67},[49,1735,1736],{"class":296},"dict",[49,1738,153],{"class":67},[49,1740,1741],{"class":1724},"update",[49,1743,144],{"class":67},[498,1745,1747],{"id":1746},"example-debugging-process","Example debugging process",[40,1749,1751],{"className":42,"code":1750,"language":44,"meta":45,"style":45},"def get_items():\n    print(\"Loading items...\")\n    # forgot to return a value\n\nitems = get_items()\n\nprint(items)\nprint(type(items))\n\nfor item in items:\n    print(item)\n",[15,1752,1753,1761,1776,1781,1785,1795,1799,1809,1823,1827,1840],{"__ignoreMap":45},[49,1754,1755,1757,1759],{"class":51,"line":52},[49,1756,321],{"class":320},[49,1758,64],{"class":324},[49,1760,328],{"class":67},[49,1762,1763,1765,1767,1769,1772,1774],{"class":51,"line":71},[49,1764,135],{"class":134},[49,1766,138],{"class":67},[49,1768,339],{"class":338},[49,1770,1771],{"class":342},"Loading items...",[49,1773,339],{"class":338},[49,1775,144],{"class":67},[49,1777,1778],{"class":51,"line":78},[49,1779,1780],{"class":792},"    # forgot to return a value\n",[49,1782,1783],{"class":51,"line":98},[49,1784,75],{"emptyLinePlaceholder":74},[49,1786,1787,1789,1791,1793],{"class":51,"line":109},[49,1788,56],{"class":55},[49,1790,60],{"class":59},[49,1792,64],{"class":63},[49,1794,68],{"class":67},[49,1796,1797],{"class":51,"line":114},[49,1798,75],{"emptyLinePlaceholder":74},[49,1800,1801,1803,1805,1807],{"class":51,"line":131},[49,1802,1053],{"class":134},[49,1804,138],{"class":67},[49,1806,1135],{"class":63},[49,1808,144],{"class":67},[49,1810,1811,1813,1815,1817,1819,1821],{"class":51,"line":819},[49,1812,1053],{"class":134},[49,1814,138],{"class":67},[49,1816,1678],{"class":296},[49,1818,138],{"class":67},[49,1820,1135],{"class":63},[49,1822,1065],{"class":67},[49,1824,1825],{"class":51,"line":832},[49,1826,75],{"emptyLinePlaceholder":74},[49,1828,1830,1832,1834,1836,1838],{"class":51,"line":1829},10,[49,1831,117],{"class":81},[49,1833,120],{"class":55},[49,1835,123],{"class":81},[49,1837,126],{"class":55},[49,1839,95],{"class":67},[49,1841,1843,1845,1847,1849],{"class":51,"line":1842},11,[49,1844,135],{"class":134},[49,1846,138],{"class":67},[49,1848,141],{"class":63},[49,1850,144],{"class":67},[20,1852,415],{},[40,1854,1856],{"className":42,"code":1855,"language":44,"meta":45,"style":45},"Loading items...\nNone\n\u003Cclass 'NoneType'>\nTraceback (most recent call last):\n  ...\nTypeError: 'NoneType' object is not iterable\n",[15,1857,1858,1866,1871,1888,1898,1902],{"__ignoreMap":45},[49,1859,1860,1863],{"class":51,"line":52},[49,1861,1862],{"class":55},"Loading items",[49,1864,1865],{"class":469},"...\n",[49,1867,1868],{"class":51,"line":71},[49,1869,1870],{"class":91},"None\n",[49,1872,1873,1876,1879,1881,1883,1885],{"class":51,"line":78},[49,1874,1875],{"class":59},"\u003C",[49,1877,1878],{"class":320},"class",[49,1880,436],{"class":338},[49,1882,482],{"class":342},[49,1884,274],{"class":338},[49,1886,1887],{"class":59},">\n",[49,1889,1890,1892,1894,1896],{"class":51,"line":98},[49,1891,456],{"class":63},[49,1893,138],{"class":67},[49,1895,461],{"class":63},[49,1897,464],{"class":67},[49,1899,1900],{"class":51,"line":109},[49,1901,470],{"class":469},[49,1903,1904,1906,1908,1910,1912,1914,1916,1918,1920],{"class":51,"line":114},[49,1905,475],{"class":296},[49,1907,241],{"class":67},[49,1909,436],{"class":338},[49,1911,482],{"class":342},[49,1913,274],{"class":338},[49,1915,487],{"class":296},[49,1917,490],{"class":59},[49,1919,493],{"class":59},[49,1921,496],{"class":55},[20,1923,1924,1925,1928,1929,153],{},"From this output, you can see that ",[15,1926,1927],{},"get_items()"," returned ",[15,1930,32],{},[20,1932,1933,1934,153],{},"If you are handling data from files or APIs, careful error handling can also help. See ",[278,1935,1937],{"href":1936},"\u002Flearn\u002Fusing-try-except-else-and-finally-in-python\u002F","using try, except, else, and finally in Python",[35,1939,1941],{"id":1940},"methods-that-change-data-in-place","Methods that change data in place",[20,1943,1944,1945,153],{},"Some methods modify an object directly and return ",[15,1946,32],{},[20,1948,1949],{},"Common examples:",[178,1951,1952,1957,1962,1967],{},[181,1953,1954],{},[15,1955,1956],{},"list.sort()",[181,1958,1959],{},[15,1960,1961],{},"list.append()",[181,1963,1964],{},[15,1965,1966],{},"list.extend()",[181,1968,1969],{},[15,1970,1971],{},"dict.update()",[20,1973,1974],{},"A common mistake is assigning the result of these methods to a variable.",[498,1976,1978],{"id":1977},"wrong","Wrong",[40,1980,1982],{"className":42,"code":1981,"language":44,"meta":45,"style":45},"numbers = [3, 1, 2]\nnumbers = numbers.sort()\n\nfor number in numbers:\n    print(number)\n",[15,1983,1984,2006,2020,2024,2036],{"__ignoreMap":45},[49,1985,1986,1988,1990,1992,1995,1997,2000,2002,2004],{"class":51,"line":52},[49,1987,1075],{"class":55},[49,1989,60],{"class":59},[49,1991,593],{"class":67},[49,1993,1994],{"class":1310},"3",[49,1996,348],{"class":67},[49,1998,1999],{"class":1310}," 1",[49,2001,348],{"class":67},[49,2003,1316],{"class":1310},[49,2005,451],{"class":67},[49,2007,2008,2010,2012,2014,2016,2018],{"class":51,"line":71},[49,2009,1075],{"class":55},[49,2011,60],{"class":59},[49,2013,1353],{"class":55},[49,2015,153],{"class":67},[49,2017,1725],{"class":63},[49,2019,68],{"class":67},[49,2021,2022],{"class":51,"line":78},[49,2023,75],{"emptyLinePlaceholder":74},[49,2025,2026,2028,2030,2032,2034],{"class":51,"line":98},[49,2027,117],{"class":81},[49,2029,1348],{"class":55},[49,2031,123],{"class":81},[49,2033,1353],{"class":55},[49,2035,95],{"class":67},[49,2037,2038,2040,2042,2044],{"class":51,"line":109},[49,2039,135],{"class":134},[49,2041,138],{"class":67},[49,2043,1364],{"class":63},[49,2045,144],{"class":67},[20,2047,2048,2051,2052,2054,2055,2057,2058,153],{},[15,2049,2050],{},"numbers.sort()"," sorts the list in place and returns ",[15,2053,32],{},", so ",[15,2056,1093],{}," becomes ",[15,2059,32],{},[498,2061,2063],{"id":2062},"correct","Correct",[40,2065,2067],{"className":42,"code":2066,"language":44,"meta":45,"style":45},"numbers = [3, 1, 2]\nnumbers.sort()\n\nfor number in numbers:\n    print(number)\n",[15,2068,2069,2089,2099,2103,2115],{"__ignoreMap":45},[49,2070,2071,2073,2075,2077,2079,2081,2083,2085,2087],{"class":51,"line":52},[49,2072,1075],{"class":55},[49,2074,60],{"class":59},[49,2076,593],{"class":67},[49,2078,1994],{"class":1310},[49,2080,348],{"class":67},[49,2082,1999],{"class":1310},[49,2084,348],{"class":67},[49,2086,1316],{"class":1310},[49,2088,451],{"class":67},[49,2090,2091,2093,2095,2097],{"class":51,"line":71},[49,2092,1093],{"class":55},[49,2094,153],{"class":67},[49,2096,1725],{"class":63},[49,2098,68],{"class":67},[49,2100,2101],{"class":51,"line":78},[49,2102,75],{"emptyLinePlaceholder":74},[49,2104,2105,2107,2109,2111,2113],{"class":51,"line":98},[49,2106,117],{"class":81},[49,2108,1348],{"class":55},[49,2110,123],{"class":81},[49,2112,1353],{"class":55},[49,2114,95],{"class":67},[49,2116,2117,2119,2121,2123],{"class":51,"line":109},[49,2118,135],{"class":134},[49,2120,138],{"class":67},[49,2122,1364],{"class":63},[49,2124,144],{"class":67},[20,2126,415],{},[40,2128,2130],{"className":42,"code":2129,"language":44,"meta":45,"style":45},"1\n2\n3\n",[15,2131,2132,2137,2142],{"__ignoreMap":45},[49,2133,2134],{"class":51,"line":52},[49,2135,2136],{"class":1310},"1\n",[49,2138,2139],{"class":51,"line":71},[49,2140,2141],{"class":1310},"2\n",[49,2143,2144],{"class":51,"line":78},[49,2145,2146],{"class":1310},"3\n",[20,2148,2149,2150,241],{},"The same problem can happen with ",[15,2151,1971],{},[40,2153,2155],{"className":42,"code":2154,"language":44,"meta":45,"style":45},"data = {\"a\": 1}\ndata = data.update({\"b\": 2})\n\nfor key in data:\n    print(key)\n",[15,2156,2157,2179,2207,2211,2224],{"__ignoreMap":45},[49,2158,2159,2161,2163,2166,2168,2170,2172,2174,2176],{"class":51,"line":52},[49,2160,1109],{"class":55},[49,2162,60],{"class":59},[49,2164,2165],{"class":67}," {",[49,2167,339],{"class":338},[49,2169,278],{"class":342},[49,2171,339],{"class":338},[49,2173,241],{"class":67},[49,2175,1999],{"class":1310},[49,2177,2178],{"class":67},"}\n",[49,2180,2181,2183,2185,2187,2189,2191,2194,2196,2198,2200,2202,2204],{"class":51,"line":71},[49,2182,1109],{"class":55},[49,2184,60],{"class":59},[49,2186,1123],{"class":55},[49,2188,153],{"class":67},[49,2190,1741],{"class":63},[49,2192,2193],{"class":67},"({",[49,2195,339],{"class":338},[49,2197,774],{"class":342},[49,2199,339],{"class":338},[49,2201,241],{"class":67},[49,2203,1316],{"class":1310},[49,2205,2206],{"class":67},"})\n",[49,2208,2209],{"class":51,"line":78},[49,2210,75],{"emptyLinePlaceholder":74},[49,2212,2213,2215,2218,2220,2222],{"class":51,"line":98},[49,2214,117],{"class":81},[49,2216,2217],{"class":55}," key ",[49,2219,123],{"class":81},[49,2221,1123],{"class":55},[49,2223,95],{"class":67},[49,2225,2226,2228,2230,2233],{"class":51,"line":109},[49,2227,135],{"class":134},[49,2229,138],{"class":67},[49,2231,2232],{"class":63},"key",[49,2234,144],{"class":67},[20,2236,2237],{},"Correct version:",[40,2239,2241],{"className":42,"code":2240,"language":44,"meta":45,"style":45},"data = {\"a\": 1}\ndata.update({\"b\": 2})\n\nfor key in data:\n    print(key)\n",[15,2242,2243,2263,2286,2290,2302],{"__ignoreMap":45},[49,2244,2245,2247,2249,2251,2253,2255,2257,2259,2261],{"class":51,"line":52},[49,2246,1109],{"class":55},[49,2248,60],{"class":59},[49,2250,2165],{"class":67},[49,2252,339],{"class":338},[49,2254,278],{"class":342},[49,2256,339],{"class":338},[49,2258,241],{"class":67},[49,2260,1999],{"class":1310},[49,2262,2178],{"class":67},[49,2264,2265,2268,2270,2272,2274,2276,2278,2280,2282,2284],{"class":51,"line":71},[49,2266,2267],{"class":55},"data",[49,2269,153],{"class":67},[49,2271,1741],{"class":63},[49,2273,2193],{"class":67},[49,2275,339],{"class":338},[49,2277,774],{"class":342},[49,2279,339],{"class":338},[49,2281,241],{"class":67},[49,2283,1316],{"class":1310},[49,2285,2206],{"class":67},[49,2287,2288],{"class":51,"line":78},[49,2289,75],{"emptyLinePlaceholder":74},[49,2291,2292,2294,2296,2298,2300],{"class":51,"line":98},[49,2293,117],{"class":81},[49,2295,2217],{"class":55},[49,2297,123],{"class":81},[49,2299,1123],{"class":55},[49,2301,95],{"class":67},[49,2303,2304,2306,2308,2310],{"class":51,"line":109},[49,2305,135],{"class":134},[49,2307,138],{"class":67},[49,2309,2232],{"class":63},[49,2311,144],{"class":67},[20,2313,2314,2315,153],{},"If you want more detail, see the ",[278,2316,2318],{"href":2317},"\u002Freference\u002Fpython-list-sort-method\u002F","Python list sort() method",[35,2320,2322],{"id":2321},"using-a-default-value-safely","Using a default value safely",[20,2324,2325],{},"Sometimes a default value is fine. Sometimes it hides a bug.",[20,2327,2328],{},"This pattern is common:",[40,2330,2332],{"className":42,"code":2331,"language":44,"meta":45,"style":45},"items = items or []\n",[15,2333,2334],{"__ignoreMap":45},[49,2335,2336,2338,2340,2342,2344],{"class":51,"line":52},[49,2337,56],{"class":55},[49,2339,60],{"class":59},[49,2341,85],{"class":55},[49,2343,1471],{"class":59},[49,2345,106],{"class":67},[20,2347,2348],{},"It can be useful when all “empty” values should behave the same way.",[20,2350,2351],{},"But be careful. This also replaces other falsey values, such as:",[178,2353,2354,2358,2363,2368],{},[181,2355,2356],{},[15,2357,1274],{},[181,2359,2360],{},[15,2361,2362],{},"\"\"",[181,2364,2365],{},[15,2366,2367],{},"0",[181,2369,2370],{},[15,2371,810],{},[20,2373,2374,2375,2377],{},"If you only want to replace ",[15,2376,32],{},", use an explicit check:",[40,2379,2381],{"className":42,"code":2380,"language":44,"meta":45,"style":45},"if items is None:\n    items = []\n",[15,2382,2383,2395],{"__ignoreMap":45},[49,2384,2385,2387,2389,2391,2393],{"class":51,"line":52},[49,2386,82],{"class":81},[49,2388,85],{"class":55},[49,2390,88],{"class":59},[49,2392,92],{"class":91},[49,2394,95],{"class":67},[49,2396,2397,2399,2401],{"class":51,"line":71},[49,2398,101],{"class":55},[49,2400,60],{"class":59},[49,2402,106],{"class":67},[20,2404,2405],{},"Use a default only when it matches the meaning of your program.",[20,2407,2408],{},"Good use case:",[178,2410,2411],{},[181,2412,2413],{},"missing items should behave like an empty list",[20,2415,2416],{},"Bad use case:",[178,2418,2419],{},[181,2420,2421,2423],{},[15,2422,32],{}," means “data failed to load” and should be handled differently",[35,2425,2427],{"id":2426},"related-errors","Related errors",[20,2429,2430],{},"You may also run into similar errors:",[178,2432,2433,2441,2449,2457],{},[181,2434,2435],{},[278,2436,13,2438],{"href":2437},"\u002Ferrors\u002Ftypeerror-int-object-is-not-iterable-fix\u002F",[15,2439,2440],{},"'int' object is not iterable",[181,2442,2443],{},[278,2444,13,2446],{"href":2445},"\u002Ferrors\u002Ftypeerror-bool-object-is-not-iterable-fix\u002F",[15,2447,2448],{},"'bool' object is not iterable",[181,2450,2451],{},[278,2452,13,2454],{"href":2453},"\u002Ferrors\u002Ftypeerror-function-object-is-not-iterable-fix\u002F",[15,2455,2456],{},"'function' object is not iterable",[181,2458,2459],{},[278,2460,2462,2463],{"href":2461},"\u002Ferrors\u002Fattributeerror-nonetype-object-has-no-attribute-fix\u002F","AttributeError: ",[15,2464,2465],{},"'NoneType' object has no attribute",[35,2467,2469],{"id":2468},"faq","FAQ",[498,2471,2473],{"id":2472},"what-is-nonetype-in-python","What is NoneType in Python?",[20,2475,2476,2478,2479,2481,2482,2484],{},[15,2477,482],{}," is the type of ",[15,2480,32],{},". ",[15,2483,32],{}," is a special value that means no value.",[498,2486,2488],{"id":2487},"why-does-python-say-none-is-not-iterable","Why does Python say None is not iterable?",[20,2490,2491,2492,2494],{},"Because looping and membership checks need an iterable object like a list, tuple, string, set, or dictionary. ",[15,2493,32],{}," is not one of these.",[498,2496,2498],{"id":2497},"can-i-fix-this-by-using-an-empty-list","Can I fix this by using an empty list?",[20,2500,2501,2502,2504],{},"Yes, but only if an empty list is the correct fallback. It is better to understand why the value became ",[15,2503,32],{}," first.",[498,2506,2508],{"id":2507},"how-do-i-know-which-line-caused-none","How do I know which line caused None?",[20,2510,2511],{},"Check the traceback, then print the variable before the failing line and trace it back to the function or assignment that created it.",[498,2513,2515],{"id":2514},"do-list-methods-return-new-lists","Do list methods return new lists?",[20,2517,2518,2519,2522,2523,2526,2527,2530,2531,153],{},"Not all of them. Methods like ",[15,2520,2521],{},"append()",", ",[15,2524,2525],{},"extend()",", and ",[15,2528,2529],{},"sort()"," change the list in place and return ",[15,2532,32],{},[35,2534,2536],{"id":2535},"see-also","See also",[178,2538,2539,2544,2548,2552],{},[181,2540,2541],{},[278,2542,2543],{"href":685},"Return values in Python functions",[181,2545,2546],{},[278,2547,1245],{"href":1244},[181,2549,2550],{},[278,2551,2318],{"href":2317},[181,2553,2554],{},[278,2555,2462,2556],{"href":2461},[15,2557,2465],{},[2559,2560,2561],"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 .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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 .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .s2W-s, html code.shiki .s2W-s{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sithA, html code.shiki .sithA{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--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}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 .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sFwrP, html code.shiki .sFwrP{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#24292E;--shiki-default-font-style:inherit;--shiki-dark:#E1E4E8;--shiki-dark-font-style:inherit}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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}",{"title":45,"searchDepth":71,"depth":71,"links":2563},[2564,2565,2566,2570,2571,2574,2581,2585,2589,2590,2591,2598],{"id":37,"depth":71,"text":38},{"id":156,"depth":71,"text":157},{"id":306,"depth":71,"text":307,"children":2567},[2568,2569],{"id":500,"depth":78,"text":501},{"id":568,"depth":78,"text":569},{"id":689,"depth":71,"text":690},{"id":907,"depth":71,"text":908,"children":2572},[2573],{"id":1098,"depth":78,"text":1099},{"id":1248,"depth":71,"text":1249,"children":2575},[2576,2577,2579,2580],{"id":1286,"depth":78,"text":1287},{"id":1369,"depth":78,"text":2578},"Fix 2: Check for None",{"id":1438,"depth":78,"text":1439},{"id":1493,"depth":78,"text":1494},{"id":1602,"depth":71,"text":2582,"children":2583},"How to debug where None came from",[2584],{"id":1746,"depth":78,"text":1747},{"id":1940,"depth":71,"text":1941,"children":2586},[2587,2588],{"id":1977,"depth":78,"text":1978},{"id":2062,"depth":78,"text":2063},{"id":2321,"depth":71,"text":2322},{"id":2426,"depth":71,"text":2427},{"id":2468,"depth":71,"text":2469,"children":2592},[2593,2594,2595,2596,2597],{"id":2472,"depth":78,"text":2473},{"id":2487,"depth":78,"text":2488},{"id":2497,"depth":78,"text":2498},{"id":2507,"depth":78,"text":2508},{"id":2514,"depth":78,"text":2515},{"id":2535,"depth":71,"text":2536},"Master typeerror nonetype object is not iterable fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Ftypeerror-nonetype-object-is-not-iterable-fix",{"title":5,"description":2599},"errors\u002Ftypeerror-nonetype-object-is-not-iterable-fix","RLLX2ujSuEinYej8Ka_dde77YlhGmDVubJGtS8qXMbM",1777585501246]