0
def print_dict(**person):
        print(person)

print_dict( a ='jack', b ='rose')
# {'a': 'jack', 'b': 'rose'}

With two asterisks, Python will create a dictionary to hold the keywords arguments. What I do not understand is why the arguments are: a = "Jack" instead of "a" = "Jack", cause a is a key, why is it not quoted?

  • 1
    https://stackoverflow.com/questions/1769403/understanding-kwargs-in-python – Keyur Potdar Mar 06 '18 at 11:47
  • 1
    No, `a` is the name of a function argument, not a dictionary key. `d['a']` and `{'a': ...}` are dictionary keys. – deceze Mar 06 '18 at 11:49
  • @deceze Don't post answers as comments, it bypasses the quality controls, and deprives you of sweet sweet answer points. – Adam Barnes Mar 06 '18 at 11:51
  • You can use `print_dict(**{'a': 'jack', 'b': 'rose'})` and get the same result, you don't have to pass it as function arguments. – user3483203 Mar 06 '18 at 11:51

0 Answers0