Код: Выделить всё
>>> a=2
>>> id(a)
13332800
>>> a=a+2 # reassigning allocates new memory
>>> id(a)
13332752
>>> a=[1,2,3,4]
>>> id(a)
139923169899008
>>> a.append(2) # change takes in place
>>> id(a)
139923169899008
>>> a=a+[3,2] # this way causes new memory allocation
>>> id(a)
139923169899656
Подробнее здесь: https://stackoverflow.com/questions/267 ... assignment