Strange behaviour of 'is'

Fijoy George tofijoy at yahoo.co.in
Thu Sep 21 17:20:46 EDT 2006


Hi all,

I am a bit perplexed by the following behaviour of the 'is' comparator

>>> x = 2.
>>> x is 2.
False
>>> y = [2., 2.]
>>> y[0] is y[1]
True

My understanding was that every literal is a constructure of an object. 
Thus, the '2.' in 'x = 2.' and the '2.' in 'x is 2.' are different objects. 
Therefore, the comparison yields false.

But my understanding does not explain the result of the second comparison. 
According to the experiment, y[0] and y[1] are the same object!

Does anyone know an explanation for this?

Thank you very much
Fijoy 





More information about the Python-list mailing list