What’s happening here?
fun(a, b) expects two parameters:
-
a
- b
-
In the function call:
fun(1, a=2)1 is passed as a positional argument
a=2 is passed as a keyword argument
❌ The Problem (Tricky Part)
Python assigns arguments in this order:
-
Positional arguments first
-
Keyword arguments second
So Python tries to assign:
1 → a
a=2 → a again ❌
➡️ This means a gets two values, which is not allowed.
Result
TypeError: fun() got multiple values for argument 'a'✅ Correct Ways to Call the Function
✔ Option 1: Use all positional arguments
print(fun(1, 2))✔ Option 2: Use all keyword arguments
print(fun(a=1, b=2))✔ Option 3: Mix (positional first, keyword next — without duplication)
print(fun(1, b=2))Key Rule to Remember (Exam Favorite )
❗ A parameter cannot receive multiple values
❗ Positional arguments must come before keyword arguments


0 Comments:
Post a Comment