title: Is there a builtin function version of `and` and/or `or` in Python?
body: <p>This question is for fun; I don't expect the answer to be useful.</p>
  
  <p>When I see people doing things with <code>reduce()</code> in Python, they often take advantage of a builtin function in Python, often from the <code>operator</code> module.</p>
  
  <p>This works:</p>
  
  <pre><code>result = reduce(lambda a, b: a + b, range(5))
  </code></pre>
  
  <p>But usually you would see this:</p>
  
  <pre><code>from operator import add
  result = reduce(add, range(5))
  </code></pre>
  
  <p>What's strange to me is that the <code>operator</code> module doesn't seem to have a function for logical <code>and</code>.  It does have <em>bitwise</em> and, but not logical <code>and</code>.</p>
  
  <p>So suppose you are doing this:</p>
  
  <pre><code>result = reduce(lambda a, b: a and b, range(1, 6))
  </code></pre>
  
  <p>Is there a builtin function that can be used here?</p>
  
  <p>I'm also wondering if there is a builtin function that can replace <code>or</code>.</p>
  
  <p>If you map the arguments to Booleans first, you can use the bitwise and from <code>operator</code>, or just directly use <code>bool.__and__</code>, like so:</p>
  
  <pre><code>from operator import and_
  result = reduce(and_, map(bool, range(1, 6)))
  result = reduce(bool.__and__, map(bool, range(1, 6)))
  </code></pre>
  
  <p>And likewise with <code>operator.or_()</code> or <code>bool.__or__</code> for the <code>or</code> operation.  But I am looking for a function that doesn't need the values mapped to Booleans.</p>
  
  <p>If you knew for certain that your values are all integers, you could use <code>operator.mul</code> for <code>and</code> and <code>operator.add</code> for <code>or</code>.  This would be a crude hack and I don't want this answer... especially considering how expensive the multiplications would get if many numbers were encountered and none of them were zero!</p>
  
  <p>Note: I am aware of <code>all()</code> and <code>any()</code>, which are better replacements for this use of <code>reduce()</code>.  As I said at the top, I'm asking this for fun.</p>
  
  <p>Note: A function that has the side-effect of forcing all values to <code>bool</code> would be an acceptable answer.  The built-in <code>and</code> keyword doesn't do this:</p>
  
  <pre><code>x = 3 and 5  # sets x to 5, not to True
  </code></pre>
  
  <p>But for the purpose of this question I am just interested in a function that can work with <code>reduce()</code> to do logical <code>and</code> or <code>or</code> operations.</p>