0 + not 0

Luuk luuk at invalid.lan
Sat Jul 11 13:30:29 CEST 2015


On 11-7-2015 13:20, Chris Angelico wrote:
> On Sat, Jul 11, 2015 at 9:12 PM, Luuk <luuk at invalid.lan> wrote:
>> It can occur in an arithmetic expression, and 'not' has a higher precedence
>> than '+'
>> (https://docs.python.org/2/reference/expressions.html#operator-precedence)
>>
>
> I think you're misreading the table; 'not' has *lower* precedence than '+'.
>
>> But, it gets confusing......
>>>>> not 0 + 1
>> False
>>>>> not 0
>> True
>>>>> True + 1
>> 2
>>>>>
>>
>> i would expect 'not 0 + 1' to return the same value as 'True + 1'
>
> (not 0 + 1) == (not (0 + 1))
>
> ChrisA
>

But operator precedence of 'not' is higher than of '+' ????


More information about the Python-list mailing list