def incr(s,a=[]):
for x in s:
a.append(x)
return a
print(incr('asmuel'))
print(incr('rainfi'))
Output:
['a', 's', 'm', 'u', 'e', 'l']
['a', 's', 'm', 'u', 'e', 'l', 'r', 'a', 'i', 'n', 'f', 'i']
Why is this function retaining the value even after setting the default parameter to be empty list? How to use the default parameter value i.e [] every time I call the function?