Here, the list is defined as a local variable in the parameter of the function foo
, but I'm confused why even on repeated calls the list still remembers it's previous values, why is it acting like a static variable?
def foo(character,my_list = []):
my_list.append(character)
print(my_list)
foo("a")
foo('b')
foo('c')
---- Output ----
['a']
['a','b']
['a','b','c']