a = b = 1 just syntactic sugar?

Batista, Facundo FBatista at uniFON.com.ar
Tue Jun 3 19:42:18 CEST 2003


#- I think if a language supports a = b = 1
#- then that means  "b = 1"  returns a value
#- of 1, which can be assigned to any variable.
#- But it seems like it is only a syntactic sugar
#- in Python?


Wrong.

>>> a = b = 2
>>> b
2
>>> a
2
>>> id(a)
135286056
>>> id(b)
135286056
>>> a is b
1

"b = 1" does not return 1, just returns b. a and b are the same object now
(they are not just equal, they are the very same).

.	Facundo





More information about the Python-list mailing list