title: Using IF, AND, OR together with EQUAL operand together in Python
body: <p>I'm trying to create a function where the given value (passed as a string) is checked to see if the number of digits is either 4 or 6, and that it is a number. </p>
  
  <p>My first impulse was to go with this code:</p>
  
  <pre><code>def number(x):
      if (len(x) == (4 or 6)) and x.isdigit():
          print "True"
      else:
          print "False"
  </code></pre>
  
  <p>This code above only passes the first test below...I don't understand why it passes this but none of the other tests:</p>
  
  <pre><code>number("1234")
  </code></pre>
  
  <p>Only when I separate out the len() functions will it work properly.</p>
  
  <pre><code>def number(x):
      if (len(x) == 4 or len(x) == 6) and x.isdigit():
          print "True"
      else:
          print "False"
  
  
  ## Checks
  number("1234")
  number("123456")
  number("abcd")
  number("abcdef")
  number("1")
  number("a")
  </code></pre>
  
  <p>The above code passes all tests.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>What's going on here?  </li>
  <li>Any way to write cleaner code for this?</li>
  </ol>
  
  <p>Thank for the help! </p>
  
  <p>** Not a duplicate question because although this question has the same underlying concepts regarding boolean operators, the problem itself is different due to the usage of len(), isdigit(), and the additional question of how best to improve it (someone commented the usage of return). Definitely adds another perspective to the other question though.</p>