xor operator?

Nicola Musatti objectway at divalsim.it
Fri Jan 26 09:24:41 EST 2001


Thomas Wouters wrote:
> 
> On Fri, Jan 26, 2001 at 05:51:41AM -0700, Def P wrote:
> 
> > I notice that there doesn't seem to be a boolean xor operator in Python. Does
> > someone know the reasons behind this?
> 
> Very few languages have a boolean xor operation. I don't know any off the
> top of my head, but if I'd have to make a guess, I'd say that INTERCAL was
> the only language I'm famialiar with, with a boolean XOR operation :)
> 
> The simple reason is 'it isn't shortcuttable'. That is, with 'and' and 'or',
> whether or not to evaluate the second argument is based on the outcome of
> the first. xor requires you to always evaluate both. In the specific Python
> sense, the return value of the boolean xor operation would also be vague.

I'd say that a more plausible reason is that for boolean values 'xor' is
equivalent to '!='. Check the already mentioned recent thread for more
Pythonic alternatives.

Best regards,
Nicola Musatti



More information about the Python-list mailing list