All Python errors
TypeError: missing 1 required positional argument
This message means a function was called with fewer values than it needs; the name of the forgotten parameter is at the end. To fix it, pass that value in the call or give the parameter a default.
Code with the error
def ticket(city, seat):
return city + ", seat " + str(seat)
print(ticket("Riga"))
Error message (Python 3.12, last line)
Corrected code
def ticket(city, seat):
return city + ", seat " + str(seat)
print(ticket("Riga", 14))
Output
Riga, seat 14
Common causes
- One argument is forgotten in the call.
- A parameter was added to the function but old calls were not updated.
- A method is called on the class itself, so self gets no value.
- A list is passed as one value although the function expects several.
Practise in the course
Lesson: FunctionsFrequently asked questions
How do I make an argument optional?
Give it a default value in the definition: def ticket(city, seat=1).
What is a positional argument?
A value matched to a parameter by its place in the call: the first to the first, the second to the second.