confused about Python assignment
Haoyu Zhang
flyfeather at myrealbox.com
Thu Oct 30 20:49:18 EST 2003
Dear Friends,
Python assignment is a reference assignment. However, I really can't
explain the difference in the following example. When the object is
a list, the assignment seems to be a reference. However, when the
object is a number, the story is so different. I don't understantd
for what reason Python deals with them differently. The example is
as follows:
>>> a = [3, 2,1]
>>> b = a
>>> a,b
([3, 2, 1], [3, 2, 1])
>>> a[1]=0
>>> a,b
([3, 0, 1], [3, 0, 1])
>>> c = 1
>>> d = c
>>> c,d
(1, 1)
>>> c=0
>>> c,d
(0, 1)
Thanks a lot.
Best,
Haoyu
More information about the Python-list
mailing list