0 + not 0

Chris Angelico rosuav at gmail.com
Sat Jul 11 13:20:13 CEST 2015


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


More information about the Python-list mailing list