Python change a value of a variable by itself.

Kurda Yon kurdayon at yahoo.com
Tue Feb 17 11:19:10 EST 2009


Hi,

I have the following simple code:
r = {}
r[1] = [0.000000]
r_new = {}
print r[1][0]
r_new[1] = r[1]
r_new[1][0] = r[1][0] + 0.02
print r[1][0]

It outputs:
0.0
0.02

it is something strange to me since in the first and second case I
output the same variable (r[1][0]) and it the two cases it has
different values (in spite on the fact, that between the 2 outputs I
did not assign a new value to the variable).

Can anybody pleas explain me this strange behavior?

Thank you in advance.



More information about the Python-list mailing list