I am wondering why, in the following snippet, the attributes in the copied object b
behave differently. b.lst
yields the updated values of a.lst
, but b.str
remains with the original value assigned to a.str
. Why is this?
>>> import copy
>>> class A(object):
... pass
...
>>> a = A()
>>> a.lst = [1, 2, 3]
>>> a.str = "Hola"
>>> b = copy.copy(a)
>>> a.lst.append(4)
>>> a.str = "Adios"
>>> print b.lst
[1, 2, 3, 4]
>>> print b.str
Hola