title: if x:, vs if x == True, vs if x is True
body: <p>Apologies if this has been asked before, but I have searched in vain for an answer to my <em>exact</em> question. Basically, with Python 2.7, I have a program running a series of geoprocessing tools, depended on what is reqested via a series of True/False variables that the user adjusts in the script e.g.</p>
  <pre><code>x = True
  
  if x:
      run function
  </code></pre>
  <p>However, I have now discovered that x does not need to be literally &quot;True&quot; for the function to run. For example:</p>
  <pre><code>In: x = True
      if x:
          print True
  
  Out: True
  
  In: x = 123
      if x:
          print True
  
  Out: True
  
  In: x = 'False'
      if x:
          print True
  
  Out: True
  
  In: x = False
      if x:
          print True
  
  Out: 
  </code></pre>
  <p>So any value other than False appears to evaluate to True, which would not be the case for if <strong>x == True</strong> or if <strong>x is True</strong>. Seeing as PEP 8 strongly recommends only using the <strong>if x:</strong> variant, can anybody explain why this behaviour occurs? It seems that if x: is more a test for &quot;if x is not False&quot; or &quot;if x exists&quot;. With that in mind, I believe I should be using if x is True: in this case, despite what PEP 8 has to say.</p>