Good evening,
I’m seeing unexpected state persistence with a function like this:
def add_item(item, items=[]):
items.append(item)
return items
Calling it twice:
add_item("apple")
add_item("banana")
returns ["apple", "banana"] on the second call instead of ["banana"]. I expected the default list to be empty each time. Why does it persist and what's the canonical way to do this ?