[Python-3000] XOR and NOT operator syntax
Nick Coghlan
ncoghlan at gmail.com
Sun Dec 23 04:13:06 CET 2007
hashcollision wrote:
> Currently,
> 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?
XOR can't be shortcircuited, so it doesn't gain from having a special
keyword the way AND and OR do. If you really want a logical XOR,
'bool(var1) ^ bool(var2)' will do the trick, or you can just write your
own xor function. In my experience, logical XOR is pretty rare anyway
(while bitwise XOR is common).
> Also,
> True & False, True | False, True ^ Fals, True != False
> works but
> !True, !False
> dosn't. Again, IMHO this is inconsistent and should be fixed.
Why? As Oleg already stated, if you want a bitwise negation, use '~'
(giving -2 and -1 respectively), if you want logical negation, use 'not'
(giving False and True respectively).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list