3>0 is True
mwilson at the-wire.com
Wed Sep 15 14:57:13 CEST 2010
Yingjie Lan wrote:
> I am not sure how to interprete this, in the interactive mode:
>>>> 3>0 is True
>>>> (3>0) is True
>>>> 3> (0 is 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)
More information about the Python-list