Keyword Arguement errror

def mycheck(name,age,h):
print(f"my name is {name}, and my age is {age},my height is {h}")

mycheck(10,name=“abcd”,age=10)

its giving error ?
Traceback (most recent call last):
File “script.py”, line 4, in
mycheck(10,name=“abcd”,age=10)
TypeError: mycheck() got multiple values for argument ‘name’

Hey @ARYAN27, yes it would give an error as you have passed 10 to name and then you have specified name="abcd" too. name can only take one value at a time. So the correct method to do this would be

def mycheck(name,age,h):
      print(f"my name is {name}, and my age is {age},my height is {h}")

mycheck(name=“abcd”,age=10,h=10)

Hope this helps.
Happy coding :slight_smile:

def check(cars,name,age):
print(f"my name is {name},my age is {age},i have cars={cars}")
check(2,name=“abcd”,age=20)

this is working ! but above one not!

above u told i know i just want to print positional arguments before keyworded but its giving error while one i send u later is working properly can u explain what mistake i havve done earlier

This is working because it is storing the value 2 inside the variable cars. But in the above case name was the first argument right ?If you want the above one to work you can do like this :

def mycheck(h,name,age):
    print(f"my name is {name}, and my age is {age},my height is {h}")

mycheck(10,name="abcd",age=10)

The arguments should match on both sides - when you declare the function and when you call it.

Hope now you understand !
Happy coding :slight_smile:

1 Like