title: How does a lambda function refer to its parameters in python?
body: <p>I am new in Python. My task was quite simple -- I need a list of functions that I can use to do things in batch. So I toyed it with some examples like</p>
  
  <pre><code>fs = [lambda x: x + i for i in xrange(10)]
  </code></pre>
  
  <p>Surprisingly, the call of </p>
  
  <pre><code>[f(0) for f in fs]
  </code></pre>
  
  <p>gave me the result like <code>[9, 9, 9, 9, 9, 9, 9, 9, 9, 9]</code>. It was not what I expected as I'd like the variable <code>i</code> has different values in different functions.</p>
  
  <p>So My question is:</p>
  
  <ol>
  <li><p>Is the variable <code>i</code> in lambda global or local?</p></li>
  <li><p>Does python has the same concept like 'closure' in javascript? I mean does each lambda here holds a reference to the <code>i</code> variable or they just hold a copy of the value of <code>i</code> in each?</p></li>
  <li><p>What should I do if I'd like the output to be <code>[0, 1, .....9]</code> in this case?</p></li>
  </ol>