Write Python. Understand every error.

Open the editor

Error guide · TypeError

TypeError: takes 1 positional argument but 2 were given

You called a function with more values than it has parameters.

Example

def greet(name):
    return "Hi " + name

print(greet("Riya", "Das"))

What Python says

TypeError: greet() takes 1 positional argument but 2 were given

As printed by Python 3.12. Other versions may word it slightly differently.

Try this code in Py-CRAFT

Why it happens

The function greet was defined to accept one value, but the call passes two. Python refuses instead of guessing which one to ignore. You can fix it either by passing fewer values or by giving the function another parameter.

How to fix it

def greet(first, last):
    return "Hi " + first + " " + last

print(greet("Riya", "Das"))

Output: Hi Riya Das

Tips

Learn the ideas behind it

Other common errors

Share this page: