[stdlib-sig] binary logical operators in operator module

R. David Murray rdmurray at bitdance.com
Sun Apr 28 00:51:46 CEST 2013


On Sat, 27 Apr 2013 15:23:40 -0700, Gary Miguel <garymm at gmail.com> wrote:
> Hi,
> This is my first time writing to a python list, so sorry if this message is
> misdirected.
> Recently I wrote something like:
> functools.reduce(lambda x, y: x and y, ...)
> and I was wondering why there is no logical and in the operator module.
> 
> (http://docs.python.org/3.3/library/operator.html)
> 
> Is there a reason for its not being there?

Yes.  The logical operators are shortcut operators, and therefore
there are no magic methods for implementing logical 'and' and 'or',
and thus no operator functions for calling them.

You may find the 'all' and 'any' built in functions to be of interest.

FYI python-list is a better list for this kind of question.  You are
likely to get faster response there to most questions.  This is more of
a development list (currently pretty quiescent).

--David


More information about the stdlib-sig mailing list