I have a function with one default argument. This default argument is updated inside the function. When I call the same function again, I see the argument takes the value which is set during the first call
What's wrong with the following code.
def fun(x, data=[]):
print "entering fun with data = ",data
data.append(x)
print "calling fun..."
fun(1)
print "calling fun..."
fun(3)
Here the output is
calling fun...
entering fun with data = []
calling fun...
entering fun with data = [1]
but I expect the output to be
enter code here
calling fun...
entering fun with data = []
calling fun...
entering fun with data = []