What's wrong with using not() in python?. I tried this
In [1]: not(1) + 1
Out[1]: False
And it worked fine. But after readjusting it,
In [2]: 1 + not(1)
Out[2]: SyntaxError: invalid syntax
It gives an error. How does the order matters?
not
is a unary operator, not a function, so please don't use the(..)
call notation on it. The parentheses are ignored when parsing the expression andnot(1) + 1
is the same thing asnot 1 + 1
.Due to precedence rules Python tries to parse the second expression as:
which is invalid syntax. If you really must use
not
after+
, use parentheses:For the same reasons,
not 1 + 1
first calculates1 + 1
, then appliesnot
to the result.