Though i have few years of experience using Python, the below question was asked in an interview, though it looked simple the actual result confused me.
def app(lst=[]):
lst.append('a')
return lst
print(app())
>> ['a']
print(app()) # Second time I am calling the same function
>> ['a'] # It would ideally be the same output
>> ['a','a'] # But the Actual Output is this
print(app()) # Third time I call the same function
>> ['a','a','a']
Can someone explain what is happening. With every new function call I expect the function to be initialized with the same defaults that are defined in the function argument. But I see it is not the case? Why?