I am new to python. I run a code like this:
def funtest(L=[]):
L.append(L)
return L
print(funtest([2]))
print(funtest([3]))
print(funtest([4]))
real output is in below.
[2, [...]]
[3, [...]]
[4, [...]]
It is not a new problem about the Mutable Default Arguments. see before: Least Astonishment” and the Mutable Default Argument
According to the Mutable Default Arguments rule, I thought the output should like this:
[2, [...]]
[2,3, [...]]
[2,3,4, [...]]
Does anyone have idea about that? Thanks