Does Python need an 'xor' operator?

Ken Peek Ken.Peek at SpiritSongDesigns.comNOSPAM
Sat Apr 13 15:44:26 EDT 2002


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






More information about the Python-list mailing list