Why does my Python function remember names from an earlier call?
TechnologyMy practice function starts with `def add_name(name, names=[]):`, appends the name and returns the list. Calling it once for a new group works. Calling it again without passing a list brings back the earlier group's name too.
I thought the empty-list default meant “start a new list for this call”. Python's tutorial says default values are evaluated once and illustrates how a mutable default can be shared across calls. Python's default-argument explanation
How should I give separate groups fresh lists while still allowing a caller to supply a list intentionally? I don't want to clear a list someone passed in just to hide the unexpected carry-over.