Skip to main content
added 3 characters in body
Source Link
mgilson
  • 312.3k
  • 70
  • 659
  • 723

No, mydict won't be changed. kwargs get unpacked into a new dictionary.

Consider the case where you have:

def print_arg(key=1, **kwargs):
    print (key)
    print (kwargs)

print_arg(**{'key':2,'foo':3,'bar':4})

In this case, it's obvious that kwargs is a different dict than you pass in because when it gets unpacked, it's missing the 'key' key.

No, mydict won't be changed. kwargs get unpacked into a new dictionary.

Consider the case where you have:

def print_arg(key=1,**kwargs):
    print key
    print kwargs

print_arg(**{'key':2,'foo':3,'bar':4})

In this case, it's obvious that kwargs is a different dict than you pass in because when it gets unpacked, it's missing the 'key' key.

No, mydict won't be changed. kwargs get unpacked into a new dictionary.

Consider the case where you have:

def print_arg(key=1, **kwargs):
    print(key)
    print(kwargs)

print_arg(**{'key':2,'foo':3,'bar':4})

In this case, it's obvious that kwargs is a different dict than you pass in because when it gets unpacked, it's missing the 'key' key.

Source Link
mgilson
  • 312.3k
  • 70
  • 659
  • 723

No, mydict won't be changed. kwargs get unpacked into a new dictionary.

Consider the case where you have:

def print_arg(key=1,**kwargs):
    print key
    print kwargs

print_arg(**{'key':2,'foo':3,'bar':4})

In this case, it's obvious that kwargs is a different dict than you pass in because when it gets unpacked, it's missing the 'key' key.