Why does using `arg=None` fix Python's mutable default argument issue?
问题 I\'m at the point in learning Python where I\'m dealing with the Mutable Default Argument problem. # BAD: if `a_list` is not passed in, the default will wrongly retain its contents between successive function calls def bad_append(new_item, a_list=[]): a_list.append(new_item) return a_list # GOOD: if `a_list` is not passed in, the default will always correctly be [] def good_append(new_item, a_list=None): if a_list is None: a_list = [] a_list.append(new_item) return a_list I understand that a