3>0 is True

Jon Siddle js at corefiling.co.uk
Wed Sep 15 09:04:24 EDT 2010


  As others have said, it's not a matter of precendence. Using the 
compiler module
you can see how python actually parses this:

3 > (0 is True)
Compare(Const(3), [('>', Compare(Const(0), [('is', Name('True'))]))])

No great surprise there.

3 > 0 is True
Compare(Const(3), [('>', Const(0)), ('is', Name('True'))])

As you can see, it's not the same. Two comparisons are being done "at 
once", not
one comparison on the result of another.

Hope this helps



On 15/09/10 13:34, Yingjie Lan wrote:
> Hi,
>
> 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.
>
> YL
>
>
>


-- 
Jon Siddle, CoreFiling Limited
Software Tools Developer
http://www.corefiling.com
Phone: +44-1865-203192




More information about the Python-list mailing list