title: Why do Python yield statements form a closure?
body: <p>I have two functions that return a list of functions. The functions take in a number <code>x</code> and add <code>i</code> to it. <code>i</code> is an integer increasing from 0-9.</p>
  
  <pre><code>def test_without_closure():
      return [lambda x: x+i for i in range(10)]
  
  
  
  def test_with_yield():
      for i in range(10):
          yield lambda x: x+i
  </code></pre>
  
  <p>I would expect <code>test_without_closure</code> to return a list of 10 functions that each add <code>9</code> to <code>x</code> since <code>i</code>'s value is <code>9</code>.</p>
  
  <pre><code>print sum(t(1) for t in test_without_closure()) # prints 100
  </code></pre>
  
  <p>I expected that <code>test_with_yield</code> would also have the same behavior, but it correctly creates the 10 functions.</p>
  
  <pre><code>print sum(t(1) for t in test_with_yield()) # print 55
  </code></pre>
  
  <p>My question is, does yielding form a closure in Python?</p>