[Tutor] about copy.copy

Luke Paireepinart rabidpoobear at gmail.com
Tue Jul 18 09:47:56 CEST 2006


linda.s wrote:
> what is the difference between b and c in the following code?
#---copyexample.py
import copy
a=[1,4,5]
b=a
c=copy.copy(a)

del(a[0])
print a
print b
print c

#---eof

output:
[4, 5]
[4, 5]
[1, 4, 5]


I.E. 'b' is just a reference to 'a', so modifying 'a' by deleting an 
element changed the value of 'b' (since they are really both just 
references to the
same data structure in memory.)


More information about the Tutor mailing list