Shallow vs Deep copies [was Re: python assignment]

Terry Reedy tjreedy at
Thu Jul 24 00:11:54 CEST 2003

"Erik Max Francis" <max at> wrote in message
news:3F1EDFA0.ED78E04F at

> immutable objects need not ever be literally copied

> Shallow copying makes a duplicate of the parent object.  Deep
> makes a duplicate of everything.

To be more exact, because first statement is true,
second_statement.replace('everything', 'all mutables'),
which is to say, 'as much as needed'.

>>> import copy
>>> l1=[(),[]]
>>> l2=copy.deepcopy(l1)
>>> for i in l1+l2: print id(i)
7669904 #same ()
8428448 #different []

Terry J. Reedy

More information about the Python-list mailing list