[Tutor] Is there any logic in this?
Righard/Riku van Roy
pluijzer at gmail.com
Sat Sep 1 15:29:32 CEST 2007
If you copy a list into another variable, and then change the second
one, the first gets changed aswell, for example:
>>> a = [10, 40, 30, 20]
>>> b = a
>>> b.sort()
>>> a
[10, 20, 30, 40]
>>> b
[10, 20, 30, 40]
or:
>>> a = [10, 40, 30, 20]
>>> b = a
>>> b[0] = 99
>>> a
[99, 40, 30, 20]
>>> b
[99, 40, 30, 20]
this happens with dictionary's too, but not with intergers, it is not
that this is a problem because I can just use...
>>> b = a[:]
...but I wonder if there is any logic behind this, I cannot find a
practical use for it, just problems.
thx, Righard
More information about the Tutor
mailing list