Code with the error

def ticket(city, seat):
    return city + ", seat " + str(seat)

print(ticket("Riga"))

Error message (Python 3.12, last line)

TypeError: ticket() missing 1 required positional argument: 'seat'

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: Functions

Frequently 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.