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