To avoid issues with mutable default values in functions, Python uses None as a default parameter value which is falsy. The or keyword allows for an empty list to be returned if no argument is provided. Alternatively, if an existing list is passed, it mutates that list directly, ensuring that modifications apply to the same instance rather than creating a new one.
Using None as a default value for mutable types prevents the mutable default value problem; the or expression helps to return an empty list if None is passed.
When using the add_to_shopping_list() function, if an existing list is passed, it directly mutates that list instead of creating a separate one.
Collection
[
|
...
]