[Python-ideas] XOR

geremy condra debatem1 at gmail.com
Wed Oct 28 00:26:50 CET 2009

On Tue, Oct 27, 2009 at 7:18 PM, Robert Kern <robert.kern at gmail.com> wrote:
> On 2009-10-27 18:07 PM, geremy condra wrote:
>> On Tue, Oct 27, 2009 at 6:46 PM, Georg Brandl<g.brandl at gmx.net>  wrote:
>>> Sturla Molden schrieb:
>>>> Why does Python have a bitwise but not a logical xor operator?
>>> How often do you need the xor operator?
>> 1) Technically, an operator is *never* needed, as its just syntactic
>> sugar.
>> 2) It sure would make crypto code look prettier, as we rely on xor
>>     operations extensively.
> No, it wouldn't. Crypto uses the bitwise xor which we already have an
> operator for: ^.

Actually, I use it primarily in the public-key context, where bitwise
comparison doesn't make a whole lot of sense.

> As I stated in the referenced thread, to me, the most compelling reason
> there is no "xor" keyword to go with "and" and "or" is that one cannot make
> an xor that shares the same short-circuiting behavior. Or the behavior of
> returning one of the operand objects rather than a coerced bool. Without
> either of those behaviors, there is little benefit to having a keyword
> operator where a trivial one-liner will suffice.

I've always tried to avoid and/or in Python for exactly that behavior.
You're right that it would be confusing, though.

Geremy Condra

More information about the Python-ideas mailing list