title: How do "and" and "or" act with non-boolean values?
body: <p>I'm trying to learn python and came across some code that is nice and short but doesn't totally make sense</p>
  
  <p>the context was:</p>
  
  <pre><code>def fn(*args):
      return len(args) and max(args)-min(args)
  </code></pre>
  
  <p>I get what it's doing, but why does python do this - ie return the value rather than True/False?</p>
  
  <pre><code>10 and 7-2
  </code></pre>
  
  <p>returns 5. Similarly, changing the and to or will result in a change in functionality. So</p>
  
  <pre><code>10 or 7 - 2
  </code></pre>
  
  <p>Would return 10.</p>
  
  <p>Is this legit/reliable style, or are there any gotchas on this?</p>