Does Python need an 'xor' operator?

Bengt Richter bokr at oz.net
Sat Apr 13 22:16:44 EDT 2002


On Sat, 13 Apr 2002 15:58:19 -0700, "Ken Peek" <Ken.Peek at SpiritSongDesigns.comNOSPAM> wrote:

>"Martin v. Loewis" <martin at v.loewis.de> wrote in message
>news:m3ofgn1avt.fsf at mira.informatik.hu-berlin.de...
>| "Ken Peek" <Ken.Peek at SpiritSongDesigns.comNOSPAM> writes:
>|
>| > I think an 'xor' operator is needed.  The 'xor'
>| > operator means 'logical-exclusive-or', and
>| > returns a 1 or 0.
>|
>| In Python 2.3, you will be able to write
>|
>|    bool(a) ^ bool(b)
>|
>| Seems pretty clear to me.
>|
>| Regards,
>| Martin
>
>You didn't read my post well enough-- we can already _DO_
>that with Python v2.2.x:
>
>(not a) ^ (not b)
>
>IMHO, neither the above, nor the future v2.3.x idiom:
>
>bool(a) ^ bool(b)
>
Hm, ^ should probably be != to return bools instead of integers?

>is as clear as:
>
>a xor b
>
>...
>
>Everyone_is_entitled_to_have_my_opinion'ly yours,
>
Well, to tie in with existing spelled-out 'and' and 'or' operations,
it should probably do something along those lines (i.e., evaluate to
one or other of the objects, not one of the boolean values used in the logic),
but I can't think of something sensible.

Regards,
Bengt Richter



More information about the Python-list mailing list