[Tutor] Python oddity

Keith Suda-Cederquist kdsudac at yahoo.com
Thu Feb 28 02:13:06 CET 2008


Hi,

I'm using iPython and I've run into an occasional problem that I don't understand.  Here is what I'm seeing:

>>aa=range(0,10)
>>bb=aa
>>print aa
[0,1,2,3,4,5,6,7,8,9]
>>print bb
[0,1,2,3,4,5,6,7,8,9]
>> # okay, everything allright at this point
>>bb[5]=0  #change bb
>>print aa
[0,1,2,3,4,0,6,7,8,9]  #aa has changed!!!
>>print bb
[0,1,2,3,4,0,6,7,8,9]

So the problem is that when I change bb, aa also changes even though I don't want it to.  Is this supposed to happen?  If it is can someone explain to me why this is a good thing?  and finally, can someone give me some advice on how to avoid or work-around this problem.

Thanks,
Keith




      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080227/1c432202/attachment-0001.htm 


More information about the Tutor mailing list