Does Python need an 'xor' operator?

John Roth johnroth at ameritech.net
Sat Apr 13 21:03:25 EDT 2002


"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.

Also, write it in terms of the new bool type, which
returns the True or False instances.

John Roth
>
>
>





More information about the Python-list mailing list