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