Why is it dangerous to use a list or a dict as a default parameter value in Python ?
Answer
In Python, a parameter's default value is evaluated only once, when the function is defined, not on every call. If that default value is a mutable object like a list or a dict, the same instance gets reused on every call that doesn't explicitly pass that argument. Any mutation of that default object during one call therefore silently persists across calls, producing unexpected behavior when you expect to start from an empty value every time.
Common trap
The classic trap is def add_item(item, bucket=[]): bucket.append(item); return bucket: every call without a bucket argument accumulates items from previous calls instead of starting from an empty list. The standard fix is to use None as the default and create the list inside the function when it's None.