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