Why should you not use a mutable default argument in Python?
Quick answer
Default argument values are evaluated once when the function is defined, so a default list or dictionary is shared between every call that does not pass its own, causing data to leak between calls.
This is one of the most common Python gotchas. The fix is to use None as the default and create a new object inside the function.
def add_item(item, items=[]): # bug: one shared list
items.append(item)
return items
add_item("a") # ['a']
add_item("b") # ['a', 'b'] <- surprise
def add_item(item, items=None): # correct
if items is None:
items = []
items.append(item)
return items