Overloading the "and" operator
tjreedy at udel.edu
Sun Mar 13 21:37:20 CET 2005
"Fredrik Bertilsson" <fredrik_bertilsson at passagen.se> wrote in message
news:31f7e57d.0503122133.b9073e1 at posting.google.com...
>I am trying to overload the "and" operatior, but my __and__ method is
> never called.
That is because, properly speaking, 'and' and 'or' are, in Python, in-line
flow-control keywords (related to 'if' and 'else'), and not operators.
Operators are abbreviated function calls. For binary operators, this means
evaluating both left and right operands and then calling the function,
which may hook into a special method, as you tried to do. 'And' and 'or',
on the other hand, try to avoid evaluating the right expression.
Terry J. Reedy
More information about the Python-list