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