thinkings on shallow copy

Kendear kendear at nospam.com
Thu Jun 19 05:38:39 EDT 2003


i was just looking at docstrings and saw the one
for copy.__doc__ regarding copy.copy():

 > - A shallow copy constructs a new compound object and then (to the
 >   extent possible) inserts *the same objects* into in that the
 >   original contains.

I wonder if it is actually to insert *the same object references*
into the new compound object...

in python, when we say

a = [1, 3, 10]

"a" is a variable whose value is a reference (a pointer) to
the object, which in this case is a list, is that correct?

so if we say
b = a

there is no difference between a and b.
they are both just a reference to the same
list object.

and there is no way we can insert the whole list
object into any python variable.  we merely
set a variable to refer to an object in RAM.

so shallow copy constructs a new compound object
and copies the references in the source compound
object to the new compound object, is that correct?






More information about the Python-list mailing list