Why do these two 'x' refer to different variable?
<p>In this code, the x in the lambda refers to the x in the for statement. So <code>y[0]()</code> returns 2:</p>

<pre><code>x = 0
y = [lambda : x for x in range(3)]
y[0]()
</code></pre>

<p>But in this code, the x in the lambda refers to global x, so <code>x[0]()</code> returns global x itself:<br /></p>

<pre><code>x = [lambda : x for x in range(3)]
x[0]()
</code></pre>

<p>I want to know why the x in the lambda refers to the local x in the first piece of code but global x in the second piece of code.</p>
