missing 'xor' Boolean operator

Dr. Phillip M. Feldman pfeldman at verizon.net
Tue Jul 14 15:56:02 EDT 2009

!= does do what I want, except that it doesn't indicate to someone reading
the code that the operands are being treated as logicals.  (Readability is
supposed to be one of the major selling points of Python).  But, this is
probably good enough.

Here's a related issue: I would like to see an option for type checking on
operands of logical operators, so that attempting to apply a logical
operator to non-Boolean entities generates a warning message.  With operand
type checking, 'xor' and != would be different.

Mark Dickinson wrote:
> On Jul 14, 7:25 pm, "Dr. Phillip M. Feldman" <pfeld... at verizon.net>
> wrote:
>> Current Boolean operators are 'and', 'or', and 'not'.  It would be nice
>> to
>> have an 'xor' operator as well.
> Hmm.  I don't think 'nice' is sufficient.  You'd need to make the case
> that it's sufficiently useful to justify adding a new keyword 'xor' to
> the language;  I suspect that would be an uphill struggle. :)
> I'll just note that:
> (1) It's easy to emulate xor:  'x xor y' <-> bool(x) != bool(y)
> (2) 'and' and 'or' are special in that they have useful short-
> circuiting behaviour; xor doesn't have this property (that is, you
> always need to evaluate *both* operands to determine the result).
> I'd also guess that 'xor' would be much less used than 'and' or 'or',
> but maybe that's just a reflection of the sort of code that I tend to
> write.
> --
> Mark
> -- 
> http://mail.python.org/mailman/listinfo/python-list

View this message in context: http://www.nabble.com/missing-%27xor%27-Boolean-operator-tp24485116p24486661.html
Sent from the Python - python-list mailing list archive at Nabble.com.

More information about the Python-list mailing list