[Python-ideas] XOR

Georg Brandl g.brandl at gmx.net
Wed Oct 28 00:14:01 CET 2009


geremy condra schrieb:
> 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.

Exactly.  Therefore it makes sense to select the most often used operations
and add syntactic sugar for them.  Boolean XOR is not one of them.  (The
thread linked by Mark enumerates a fair number of equivalent spellings,
but the most important thing is that it's impossible to make the "xor"
behave equivalent to "and" and "or" in terms of short-circuiting and
returning one of the operands.)

> 2) It sure would make crypto code look prettier, as we rely on xor
>     operations extensively.

We *do* have a bitwise xor.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.




More information about the Python-ideas mailing list