0 + not 0
Luuk
luuk at invalid.lan
Sat Jul 11 07:12:54 EDT 2015
On 11-7-2015 12:38, Irmen de Jong wrote:
> On 11-7-2015 12:26, candide wrote:
>>>>> 0 + not 0
>> File "<stdin>", line 1
>> 0 + not 0
>> ^
>> SyntaxError: invalid syntax
>>>>>
>>
>>
>> What is syntactically wrong with 0 + not 0?
>>
>
> I would say that the boolean operator 'not' cannot occur in an arithmetic expression.
> Maybe you meant to use the bitwise not:
>
>>>> 0 + ~0
> -1
>
>
> Irmen
>
It can occur in an arithmetic expression, and 'not' has a higher
precedence than '+'
(https://docs.python.org/2/reference/expressions.html#operator-precedence)
0 + not 0
should evalutate to
0 + True
1
just like this does:
0 + (not 0)
1
True + True
2
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'
More information about the Python-list
mailing list