Going through the python tutorial, in section 4.7.1, a mutable default argument is stored somewhere but I can't seem to find it using dir()
, globals()
, locals()
or f.__dict__
. I'm referring to this code:
def f(a, L=[]):
L.append(a)
return L
behaves as:
>>> print(f(1))
[1]
>>> print(f(2))
[1, 2]
>>> print(f(3))
[1, 2, 3]
I would expect to see this in the namespace of the function, say when I do dir(f)
but it is not there.
I had a look at this but this is way more than I'm probably looking for.