Write Python. Understand every error.

Open the editor

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.

Try this code in Py-CRAFT

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

Learn the ideas behind it

Other common errors

Share this page: