Does Python need an 'xor' operator?

Steve Holden sholden at holdenweb.com
Mon Apr 15 09:34:26 EDT 2002


"Bengt Richter" <bokr at oz.net> wrote ...
[ ... ]
> 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.
>
Since in Boolean terms a xor b is equivalent to ((a and not b) or (b and not
a)), maybe a xor b should return whichever of a or b is not false.

>>> a = 42
>>> b = 0
>>> a ^ b
42
>>> b ^ a
42
>>>

Since that's exactly what it appears to do, stop fiddling with what already
works !

regards
 Steve







More information about the Python-list mailing list