TypeError: missing required positional argument (Fix)

This error happens when Python expects an argument, but your code does not provide it.

It usually appears when you call a function or method with too few values. The message often tells you exactly which parameter is missing.

Quick fix

def greet(name):
    print("Hello", name)

greet("Sam")  # pass the required argument

If a function expects one or more required positional arguments, you must provide them when calling it unless the function defines default values.

What this error means

TypeError: missing required positional argument means:

  • Python expected an argument that was not provided
  • A positional argument is matched by its position in the function call
  • The error usually names the missing parameter
  • It can happen with your own functions, class methods, or built-in/library code

For example, if a function needs two arguments, you must pass both:

def add(a, b):
    return a + b

print(add(2, 3))

Output:

5

If you leave one out, Python cannot complete the call.

Why it happens

This error usually happens for one of these reasons:

  • You called a function with too few arguments
  • You forgot that a method also needs values after the object name
  • You created a class method but forgot the self parameter in the method definition or misused it when calling
  • You changed a function definition but did not update all places that call it
  • You passed keyword arguments for some parameters but still left a required one out

If you are new to this topic, it helps to review function parameters and arguments in Python and default and keyword arguments.

Example that causes the error

Here is a simple example.

def multiply(a, b):
    return a * b

print(multiply(4))

Output:

TypeError: multiply() missing 1 required positional argument: 'b'

What happened:

  • The function multiply(a, b) requires two values
  • The call multiply(4) only provides one
  • Python raises TypeError because the argument for b is missing

How to fix it

Pass all required arguments

The most direct fix is to pass every required argument.

def multiply(a, b):
    return a * b

print(multiply(4, 5))

Output:

20

Check the function definition

Look at the function definition and count the required parameters.

def greet(first_name, last_name):
    print("Hello", first_name, last_name)

greet("Sam", "Lee")

If the function has two required parameters, the call must include two arguments.

Use keyword arguments for clarity

Keyword arguments can make the call easier to read.

def greet(first_name, last_name):
    print("Hello", first_name, last_name)

greet(last_name="Lee", first_name="Sam")

This still passes all required values, but by name instead of position.

Add a default value if the argument should be optional

If a parameter should not be required, give it a default value.

def greet(name="Guest"):
    print("Hello", name)

greet()
greet("Sam")

Output:

Hello Guest
Hello Sam

This is a common fix when you are designing your own functions. See how to create a simple function in Python for a beginner-friendly walkthrough.

If the error comes from a method, call it correctly

Methods belong to objects. You usually call them on an instance.

class User:
    def show(self, name):
        print("User:", name)

user = User()
user.show("Sam")

In this example:

  • user is the instance
  • Python passes self automatically
  • You only need to pass the remaining required argument: "Sam"

Special case: methods and self

This error is common when working with classes.

Instance methods receive self automatically

When you define an instance method, the first parameter is usually self.

class User:
    def show(self, name):
        print(name)

user = User()
user.show("Sam")

You do not pass self yourself in a normal method call.

Do not call the method incorrectly on the class

This can cause an argument mismatch.

class User:
    def show(self, name):
        print(name)

user = User()

# Correct
user.show("Sam")

If you call the method on the class instead of the instance, you may get confusing errors because Python is no longer filling self for you in the usual way.

Make sure the method definition is correct

If you forget self in the method definition, the parameters will not line up correctly.

class User:
    def show(name):  # incorrect
        print(name)

user = User()
user.show()

This method definition is wrong for a normal instance method. If you are learning functions first, start with Python functions explained before moving deeper into classes.

How to debug it step by step

When you see this error, use this checklist:

  1. Read the full error message and note the missing parameter name
  2. Find the exact line where the function or method is called
  3. Compare the call with the function definition
  4. Count how many required parameters exist
  5. Check whether some parameters already have default values and which do not
  6. If using an editor, hover over the function name or use help() to inspect the signature

Useful debugging commands:

help(function_name)
print(function_name)
print(type(object_name))
print(vars(object_name))

If you want to print the full traceback inside a larger program:

import traceback

try:
    def greet(name):
        print("Hello", name)

    greet()
except Exception:
    traceback.print_exc()

Common mistakes

These are the most common causes of this error:

  • Calling a function with too few arguments
  • Forgetting one argument after editing a function definition
  • Calling an instance method incorrectly
  • Assuming a parameter is optional when it is not
  • Mixing positional and keyword arguments and leaving one out

A related problem is passing the wrong parameter name. If that happens, see TypeError: unexpected keyword argument.

FAQ

What is a positional argument in Python?

It is an argument matched to a parameter by its position in the function call, such as the first or second value passed.

Can I fix this by using keyword arguments?

Yes. If you provide the missing required parameter by name, the call can be clearer and easier to read.

Why does this happen with class methods?

Methods have specific parameters too. For instance methods, Python passes self automatically when you call the method on an object.

How do I make an argument optional?

Give the parameter a default value in the function definition, such as name="Guest".

See also