0

The list (array) inside a python function is taking value from previous instance of function call when the value is not passed as argument. For eg.

def abc(val, y=[]):
   y.append(val)
   return y
print(abc(3))  # Output: [3]
print(abc(4, [1,2]))  # Output : [1, 2, 4]
print(abc(10))  # Output: [3, 10]  # Expected value was [10]

Can anybody please explain why y holds value from previous call when it is not passed as argument?

0 Answers0