0

guys i just checked out the **kwargs and *args method of giving arguments...i tried but its not working..plz check why

https://code.sololearn.com/cBg35yV9OEr6/?ref=app

11th May 2020, 7:45 PM
PRO
PRO - avatar
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"})
11th May 2020, 8:14 PM
andriy kan
andriy kan - avatar
+ 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")
11th May 2020, 8:03 PM
Lothar
Lothar - avatar
+ 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
11th May 2020, 8:49 PM
Lothar
Lothar - avatar
+ 2
PRO You just need to add a "_" to make female_ps and it runs fine.
11th May 2020, 8:26 PM
Russ
Russ - avatar
+ 2
PRO You are welcome
11th May 2020, 8:45 PM
andriy kan
andriy kan - avatar
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
11th May 2020, 8:08 PM
PRO
PRO - avatar
0
Lothar i tried ur method it gives an error too
11th May 2020, 8:10 PM
PRO
PRO - avatar
0
andriy kan ohh..thnx buddy
11th May 2020, 8:40 PM
PRO
PRO - avatar