Python error explained
TypeError: what it means and how to fix it
You called a function with the wrong number of arguments.
The message
TypeError: area() missing 1 required positional argument: 'height'
What it means
Every parameter in a def line needs a value when the function is called, unless it has a default. Python tells you which function and which parameter is missing.
Common causes
- Leaving out an argument
- Passing arguments in a list instead of separately
- Forgetting self when calling a method on the class rather than an object
Example that raises it
def area(width, height):
return width * height
print(area(4))
The fix
def area(width, height):
return width * height
print(area(4, 3))
Tip: If an argument is usually the same, give it a default: def area(width, height=1).
Fix the broken version yourself in the editor on this page. It runs real Python in your browser.