TypeError
TypeError: function() got multiple values for argument 'x'
Traceback
Traceback (most recent call last):
File "main.py", line 4, in <module>
greet("Alice", name="Bob")
TypeError: function() got multiple values for argument 'x'What causes this error
An argument was provided both positionally and as a keyword argument. The function received the same parameter from two sources.
How to fix it
Remove the duplicate — pass the argument either positionally or as a keyword, not both. Check for conflicts between *args unpacking and keyword arguments. In methods, use instance.method() instead of Class.method(instance).
Code that causes this error
def greet(name, greeting="Hi"):
print(f"{greeting}, {name}")
greet("Alice", name="Bob")Fixed code
def greet(name, greeting="Hi"):
print(f"{greeting}, {name}")
greet(name="Alice", greeting="Hey")About TypeError
This TypeError occurs when the same argument is provided both as a positional argument and as a keyword argument. Python cannot determine which value to use, so it raises an error. This commonly happens in class methods where `self` is passed explicitly (e.g., calling `MyClass.method(instance, x=1)` where self takes the position and x also gets a positional value), when using `*args` unpacking along with keyword arguments, and when the function parameter names overlap with keyword arguments in ways the caller did not intend.
The error message specifies which argument received multiple values, making it straightforward to identify the duplicate.
Common scenarios
Performing operations between incompatible types like strings and integers
Calling methods that return None and chaining operations on the result
Passing the wrong number or type of arguments to a function
Using bracket notation on objects that do not support indexing