title: What version of this Python code is faster?
body: <p>Just an academic question. I'm curious what version of this code is better (faster) in Python?</p>
  
  <pre><code>var = random.randint(1, 10)
  # First version
  if var in [2, 5, 9]:
    print "First: 2, 5 or 9"
  
  # Second version
  if var == 2 or number == 5 or number == 9:
    print "Second: 2, 5 or 9"
  </code></pre>
  
  <p>This is very simple example, but what if variable <code>var</code> is not a number, but string?</p>
  
  <pre><code>var = 'aaa'
  # First version
  if var in ['aaa', 'zzz', 'eee']:
    print "String"
  </code></pre>
  
  <p>What about some more complicated objects (not only numbers or string, but some class with very time-consuming comparison)?</p>
  
  <p>And what happens inside Python compiler? I suppose <code>if var in list</code> is executed like:</p>
  
  <pre><code>for l in list:
    if l == var:
      print "String"
  </code></pre>
  
  <p>So in my opinion both versions in first example are the same (speed). Am I right?</p>