My question might seem weird and ambiguous, check the following code:
def foo():
for _ in range(4):
x = []
print(id(x))
some_handler(x)
On console you would see, for example:
4319661960
4319191112
4319661960
4319191112
As well known, id()
gives an opaque value as identifier to object. In the code snippet above, I do expect four different value thus I actually initiate x to be an empty list, so I will do something to it later in some_handler() function. Now I cannot, because x will keep historical value from previous run in the loop.
I many time get tuck into some obvious and silly trap. What I got wrong here?