Does Python need an 'xor' operator?

phil hunt philh at comuno.freeserve.co.uk
Sun Apr 14 14:03:30 EDT 2002


On Sat, 13 Apr 2002 21:03:25 -0400, John Roth <johnroth at ameritech.net> wrote:
>
>"Ken Peek" <Ken.Peek at SpiritSongDesigns.comNOSPAM> wrote in message
>news:3cb88af1 at news.mhogaming.com...
>> I think an 'xor' operator is needed.  The 'xor' operator means
>> 'logical-exclusive-or', and returns a 1 or 0.
>>
>> Here is some code that does what I want (in all the cases I can think
>of) for
>> 'xor':
>>
>> # logical-exclusive-or operator:
>> def xor(a,b):
>>     return (not a) ^ (not b)
>>
>> This will work, but I think it is less clear (in an expression) than:
>'a xor b'.
>
>Write a PEP. I've got no objection, but you will get
>the usual slew of objections from people that think
>that it is too minor to warrent breaking code by
>introducing a new operator.

How will it break code to introduce a new operator? Any existing 
program that uses xor will be a syntax error, and broken already.

-- 
<"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><">
"I would guess that he really believes whatever is politically 
advantageous for him to believe." 
                        -- Alison Brooks, referring to Michael
                              Portillo, on soc.history.what-if



More information about the Python-list mailing list