[Python-ideas] XOR

Bruce Leban bruce at leapyear.org
Tue Oct 27 23:56:20 CET 2009


-1

It would be unnice in my opinion because it would falsely suggest some kind
of parallelism with how 'and' and 'or' work.

Just use bool(x) ^ bool(y) if you really want xor behavior:

>>> bool(3) ^ bool(4)
False
>>> bool(3) ^ bool(None)
True

--- Bruce
http://www.vroospeak.com


On Tue, Oct 27, 2009 at 3:48 PM, Chris Rebert <pyideas at rebertia.com> wrote:

> On Tue, Oct 27, 2009 at 3:41 PM, Sturla Molden <sturla at molden.no> wrote:
> > Why does Python have a bitwise but not a logical xor operator? It's even
> > weirder because boolean objects do have a __xor__ method.
>
> It would be nice for symmetry, but it would be infrequently used
> compared to the other operators and is not strictly necessary as
> logical XOR cannot and would not short-circuit, unlike logical AND and
> OR.
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20091027/2d6d184c/attachment.html>


More information about the Python-ideas mailing list