Python documentation says "For each such variable, a cell object is created to store the value; the local variables of each stack frame that references the value contains a reference to the cells from outer scopes which also use that variable. "
So it seems that the cell object store the value of variables(like stored the copy of the value I assume?).
but when I run this:
def func():
l = [1,2,3]
def g():
print(l)
return l,g
l,g = func()
l[0]=-1
g()
The output is:
[-1, 2, 3]
The change of l
does affect the value stored within the cell object. Then it seems to me that what was stored in the cell is the reference. Can someone explain this, please?