overloading logical not, and, or

C. Laurence Gonsalves clgonsal at kami.com
Tue Jan 29 01:40:30 EST 2002


On Mon, 28 Jan 2002 17:51:15 GMT, Terry Reedy <tjreedy at home.com> wrote:
>
> "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.
[...]
> 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.

In addition, the 'and' and 'or' operators do "short circuiting". ie:
they don't always evaluate their second parameter, depending upon the
value of the first parameter. This makes them more than normal
operators; they also implement control flow.  There isn't an immediately
obvious way that could be simulated with __and__ and __or__ methods.

-- 
  C. Laurence Gonsalves
  clgonsal at kami.com



More information about the Python-list mailing list