overloading logical not, and, or

Terry Reedy tjreedy at home.com
Mon Jan 28 12:51:15 EST 2002


"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> wrote in message
news:8be7693c.0201280103.65eafd09 at posting.google.com...
> It strikes me as rather odd that Python does not support
> overloading of the logical operators not, and and or.
> Is there a fundamental reason for this, or could a PEP
> help to change this?

'+', etc, needs to be overloadable with __add__ since it is not
otherwise for class instances.  The logical operators are defined for
everything (via their truth values) and so overloading is not needed,
nor, very obviously, even sensible (unless one wanted another means to
horribly obfuscate code).  In the expression 'a and b', 'and' operates
on truth-value(a) rather than on a itself.

Terry J. Reedy






More information about the Python-list mailing list