title: Why does 1 == True but 2 != True in Python?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2764017/is-false-0-and-true-1-in-python-an-implementation-detail-or-is-it-guarantee">Is False == 0 and True == 1 in Python an implementation detail or is it guaranteed by the language?</a>  </p>
  </blockquote>
  
  
  
  <p>A brief transcript from my interactive console:</p>
  
  <pre><code>Python 2.7.2 (default, Jun 29 2011, 11:10:00) 
  [GCC 4.6.1] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; True
  True
  &gt;&gt;&gt; 0 == True
  False
  &gt;&gt;&gt; 1 == True
  True
  &gt;&gt;&gt; 2 == True
  False
  </code></pre>
  
  <p>Why on earth is this the case?</p>
  
  <p><strong>Edit:</strong> For the sake of contrast, consider the <code>is</code> operator.</p>
  
  <pre><code>&gt;&gt;&gt; 0 is False
  False
  &gt;&gt;&gt; 1 is True
  False
  &gt;&gt;&gt; 0 is 0
  True
  &gt;&gt;&gt; True is True
  True
  </code></pre>
  
  <p>That makes a lot of sense because though <code>1</code> and <code>True</code> both mean the same thing as the condition of an <code>if</code> statement, they really aren't the same thing.</p>
  
  <p><strong>Edit again:</strong> More fun consequences of <code>1 == True</code>:</p>
  
  <pre><code>&gt;&gt;&gt; d = {}
  &gt;&gt;&gt; d[True] = "hello"
  &gt;&gt;&gt; d[1]
  "hello"
  </code></pre>