2

Notice that if you negate a boolean value with not in comparison with other boolean value or similar, you should put it inside a pair of parenthesis, otherwise you get syntax error:

>>> 0 == not 1
SyntaxError: invalid syntax
>>> 0 == (not 1)
True
>>> 

Edited by pyTony

4
Contributors
4
Replies
12
Views
4 Years
Discussion Span
Last Post by ZZucker
Featured Replies
  • The interpreter only obeys python's grammar which says that both sides of a comparison operator must be "or_expr"s (one of python's syntactic categories). An expression like `not ...` can not be considered an or_expr. With parenthesis, it becomes an "atom", which can be considered as an "or_expr". Grammar is a … Read More

1

The interpreter only obeys python's grammar which says that both sides of a comparison operator must be "or_expr"s (one of python's syntactic categories). An expression like not ... can not be considered an or_expr. With parenthesis, it becomes an "atom", which can be considered as an "or_expr".
Grammar is a cold mechanism, don't think python does anything clever here :)

0

not is expression operator, and there can not also be applied type operators, even it is like function

>>> type(not)
SyntaxError: invalid syntax
>>> type(+)
SyntaxError: invalid syntax
>>> True == --1
True
>>> def not_(e):
    return not e

>>> type(not_)
<type 'function'>
>>> 0 == not_(1)
True

Edited by pyTony

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.