Error guide · TypeError
TypeError: missing 1 required positional argument
You called a function with fewer values than it needs.
Example
def area(w, h): return w * h print(area(4))
What Python says
TypeError: area() missing 1 required positional argument: 'h'
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
A function defined with two parameters needs two values every time it is called, unless a parameter has a default. Here area(4) supplies only w, so h is missing. The message names the missing parameter, which tells you exactly what to add.
How to fix it
def area(w, h): return w * h print(area(4, 5))
Output: 20
Tips
- Count the parameters in the
defline and the values in the call. - Give a parameter a default, as in
def area(w, h=1), if it is optional. - Values are matched by position, so keep them in the same order as the parameters.