Function defaults are evaluated once, when the function is defined.
The same mutable object is then shared across all calls to the function. If the object is modified, those modifications will persist across calls, which can lead to unexpected behavior.
Instead, prefer to use immutable data structures, or take None as a default, and initialize a new mutable object inside the function body for each call.
Function defaults are evaluated once, when the function is defined.
The same mutable object is then shared across all calls to the function. If the object is modified, those modifications will persist across calls, which can lead to unexpected behavior.
Instead, prefer to use immutable data structures, or take None as a default, and initialize a new mutable object inside the function body for each call.