Does Python need an 'xor' operator?

John Roth johnroth at ameritech.net
Mon Apr 15 08:47:17 EDT 2002


"Tim Peters" <tim.one at comcast.net> wrote in message
news:mailman.1018819588.582.python-list at python.org...
> I doubt that a new "xor" operator will ever get in (compelling use
cases are
> conspicuous by absence), but anyone pushing for it had better push for
a new
> "eqv" operator too (that is, if you're going to claim that it's ugly
that
> x^y may not return one of its argument, surely it's just as ugly that
the
> same holds for x==y).
>

I don't see why, other than providing a 'complete' set of operators.
'and' and 'or' short circuit and return one of their two
operands. 'xor' obviously can't short circuit, but it can be defined
to return the 'true' operand, otherwise False, which seems to be
reasonable, and reasonably consistent with the way 'and' and 'or'
work.

'eqv', however, can neither short circuit, nor is there an obvious
selection of which operand to return when it is true.

Also, 'eqv' is not really a substitute for '=='. Eqv should
be: bool(x) == bool(y), if we follow the behavior of 'and' and 'or'.
In other words 6 eqv 7 is true, since bool(6) == bool(7).

John Roth
>
>





More information about the Python-list mailing list