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.
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
- Compare the
defline with the call: the numbers of values must match. - If you meant one piece of text containing a space, put it inside one set of quotes.
- Use default values for optional parameters so that both short and long calls work.