3>0 is True

Michael Ricordeau michael.ricordeau at gmail.com
Wed Sep 15 09:03:31 EDT 2010


Not really true for ">" and "is" :
 http://docs.python.org/reference/expressions.html#evaluation-order
Operator ">" and operator "is" are in the same precedence but in group Comparisons :
 "Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right — see section Comparisons"
 The important words here are :
 "all have the SAME PRECEDENCE and chain from left to right"
 See also :
 http://docs.python.org/reference/expressions.html#comparisons
So for :
 >>> 3 > 0 is True
 #first evaluation is :
 >>> 3 > 0 ---> True
 #second evaluation is :
 >>> 0 is True ---> False (and second evaluation is not result of first one !)
Le 2010年9月15日 14:47:11 +0200,
Michael Ricordeau <michael.ricordeau at gmail.com> a écrit :
> Because "is" operator take precedence on ">" operator .
>> Le 2010年9月15日 05:34:06 -0700 (PDT),
> Yingjie Lan <lanyjie at yahoo.com> a écrit :
>> > 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
> > 
> > 
> > 



More information about the Python-list mailing list

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