Weird expression result
Peter Otten
__peter__ at web.de
Mon Aug 18 12:27:53 EDT 2008
Dan Lenski wrote:
> On Mon, 18 Aug 2008 18:04:32 +0200, Peter Otten wrote:
>> This works just like a < b < c:
>>
>>>>> 3 in [3] and [3] == True
>> False
> Interesting. I agree with the OP that it is confusing!
>
> Does this expansion really get invoked every time there is an expression
> of the form??
>
> expr1 binary_op1 expr2 binary_op2 expr3 ...
>
> Seemingly, the answer is yes:
>
> >>> 3 in [3] in [[3],[4]] in [[[3],[4]],5] == [[[3],[2+2]],5]
> True
>
> How does this play with standard precedence rules?
Simple, all comparisons have the same priority:
http://docs.python.org/ref/comparisons.html
Peter
More information about the Python-list
mailing list