3>0 is True
Peter Otten
__peter__ at web.de
Wed Sep 15 08:46:07 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.
http://docs.python.org/reference/expressions.html#notin
"""
Unlike C, all comparison operations in Python have the same priority, which
is lower than that of any arithmetic, shifting or bitwise operation. Also
unlike C, expressions like a < b < c have the interpretation that is
conventional in mathematics:
comparison ::= or_expr ( comp_operator or_expr )*
comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!="
| "is" ["not"] | ["not"] "in"
Comparisons yield boolean values: True or False.
Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x
< y and y <= z, except that y is evaluated only once (but in both cases z is
not evaluated at all when x < y is found to be false).
"""
Peter
More information about the Python-list
mailing list