3>0 is True

Mel mwilson at the-wire.com
Wed Sep 15 08:57:13 EDT 2010


Yingjie Lan wrote:
> I am not sure how to interprete this, in the interactive mode:
>>>>> 3>0 is True
> False
>>>> (3>0) is True
> True
>>>> 3> (0 is True)
> True
>> Why did I get the first 'False'? I'm a little confused.
>> Thanks in advance for anybody who shed some light on this.

This looks like comparison chaining. `is` is a comparison operator, like 
`>`, and chains of comparisons are handled differently.
`a < b < c` is equivalent to `(a < b) and (b < c)`
Therefore the first expression is testing
(3 > 0) and (0 is True)
	Mel.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /