[Python-ideas] XOR

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Oct 28 00:18:44 CET 2009


On Tue, Oct 27, 2009 at 6:41 PM, Sturla Molden <sturla at molden.no> wrote:
> Why does Python have a bitwise but not a logical xor operator?

.. because it does:  !=

>>> True != True
False
>>> True != False
True
>>> False != False
False

In 2.x you can even use <> if you like syntactic sugar. :-)

On arbitrary types a xor b is arguably bool(a) != bool(b) rather than
simple a != b, but it is rare enough to warrant additional syntax.

I thought I've seen this answered in an FAQ list somewhere.



More information about the Python-ideas mailing list