In Python, boolean operators are and, or not
I didn’t find anywhere in the documentation where the operators can be used as statements or functions; yet this does not throw any errors?
>>> not(1)
False
But this does
>>> and(1)
SyntaxError: Invalid Syntax
Is there something I am missing about () that allows that to work?
That works for the same reason that this works:
Namely, the parens act as a grouping operator, not to indicate a function call. Anywhere that an expression is legal, parens are also legal and serve to explicitly group together one entire expression, which can be used to override the precedence of other operators (as in
(x + y) * z, which is not the same asx + y * z— the latter being equivalent tox + (y * z)).andrequires two arguments, which is whyand(1)is a syntax error — you only specified one argument.(x) and (y), however, is legal.