[Python-3000] XOR and NOT operator syntax
phd at phd.pp.ru
Sat Dec 22 21:31:05 CET 2007
On Sat, Dec 22, 2007 at 03:15:43PM -0500, hashcollision wrote:
> True or False
> works as expected, but
> True xor False
> is invalid. I don't see a reason why and, or, not are valid python keywords
> but xor is not. Can this be added in python 3.0 for completeness?
> True & False, True | False, True ^ Fals, True != False
> works but
> !True, !False
> dosn't. Again, IMHO this is inconsistent and should be fixed.
"There should be one-- and preferably only one --obvious way to do it."
- from "The Zen of Python, by Tim Peters".
There are bitwise operations and boolean operations in Python, and for an
every operation there is one and only one keyword or an operator.
'&', '|', '^' are bitwise operators. "and" and "or" are short-circuiting
boolean operators. They are not equivalent, are not interchangeable.
"not" is an unary boolean operator. Bitwise "not" is spelled '~'. Again,
they are not interchangeable.
There is no need to have a bitwise "not" as '~' is already exists. And
there is no way to have a boolean short-circuiting "xor" - hence there is
only bitwise '^' and there is no corresponding keyword.
Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-3000