Mutability of the **kwargs argument in Python
问题 Consider a case where I change the kwargs dict inside a method: def print_arg(**kwargs): print kwargs.pop('key') If I call the method pop_arg with a dictionary like this: mydict = {'key':'value'} print_arg(**mydict) will mydict be changed by this call? I am also interested in a more detailed explanation of the underlying method calling mechanism that lets mydict change or not. 回答1: Let's see: import dis dis.dis(lambda: print_arg(**{'key': 'value'})) 6 0 LOAD_GLOBAL 0 (print_arg) 3 BUILD_MAP 1