[Tutor] Copying Variables
naheed arafat
naheedcse at gmail.com
Mon Jul 25 17:17:19 CEST 2011
I got a question in this context.
suppose
a={'a': 3, 'b': [1, 2], 5: 100}
------------------b=a -------------- vs----------
b=copy.copy(a)------------
----------------------------------------------------
b[5]=6 ---------------------------------------- b[5]=6
output: ----------------------------------------- output:
b={'a': 3, 'b': [1, 2], 5: 6}------------------- b={'a': 3, 'b': [1, 2],
5: 6}
a={'a': 3, 'b': [1, 2], 5: 6} ------------------- a={'a': 3, 'b': [1, 2],
5: 100}
that means b=a & b=copy.copy(a) aren't the same.
but
b['b'].append(3)
output:
b={'a': 3, 'b': [1, 2, 3], 5: 100}--------------b={'a': 3, 'b': [1, 2, 3],
5: 100}
a={'a': 3, 'b': [1, 2, 3], 5: 100}--------------a={'a': 3, 'b': [1, 2, 3],
5: 100}
now doesn't it mean that b=a & b=copy.copy(a) both are same?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110725/7702794b/attachment.html>
More information about the Tutor
mailing list