0
guys i just checked out the **kwargs and *args method of giving arguments...i tried but its not working..plz check why
8 ответов
+ 5
Named arguments are sent using the
name=value
syntax.
An argument name should be defined according to the Python naming rules, but in your code you are using a string as argument name.
The named arguments should be used like this:
award_show(actor="leo di caprio", female_ps="brandi love", phone="i phone 11 pro max", car="tesla model y")
Or if you want to use dictionary syntax for argument names then you should use unpacking operator (**), like this:
award_show(**{"actor":"leo di caprio", "female ps":"brandi love", "phone":"i phone 11 pro max", "car":"tesla model y"})
+ 3
The code has to be like this:
def award_show(**best_things):
for keys, values in best_things.items():
print(f"best {keys} is {values}")
award_show(actor="leo di caprio", female_ps="brandi love", phone="i phone 11 pro max", car="tesla model y")
+ 3
PRO, the code i posted does work without problem, and gives the following result:
best actor is leo di caprio
best female_ps is brandi love
best phone is i phone 11 pro max
best car is tesla model y
So i put it for your convenience in a file, so that you only have to press the run button:
https://code.sololearn.com/cwq0UJ0vYTJM/?ref=app
+ 2
PRO You just need to add a "_" to make female_ps and it runs fine.
+ 2
PRO
You are welcome
0
Lothar but bro i read that **kwargs takes a dictionary as input...and we make dictionary like {"key1":"value1", "key2":"value2"}...so why do we pass argument like that
0
Lothar i tried ur method it gives an error too
0
andriy kan ohh..thnx buddy