mutable_default()
Append a marker value to a list and return it.
Usage
mutable_default(items=None)If no list is provided, an internal default list is used. Appends the string "added" to the list and returns it.
Parameters
items: list = None-
A list to append to. If
None, a new empty list is created for each call.
Returns
list-
The list with
"added"appended.
Warnings
If you modify this function to use a mutable default argument (e.g., items=[]), the default empty list would be shared across all calls that omit the argument. Each call would mutate the same list object, leading to surprising accumulation of values.
Always use None as the default and create a new list inside the function body to avoid this pitfall.
Examples
>>> mutable_default()
['added']>>> mutable_default(["existing"])
['existing', 'added']