How to define free-variable in python?
<p>The <strong>local/global/free variable</strong> definitions from <a href="http://docs.python.org/py3k/reference/executionmodel.html" rel="nofollow">python doc</a>:</p>

<blockquote>
  <p>If a name is bound in a block, it is a <strong>local variable</strong> of that block, unless declared as nonlocal. If a name is bound at the module level, it is a <strong>global variable</strong>. (The variables of the module code block are local and global.) If a variable is used in a code block but not defined there, it is a <strong>free variable</strong>.</p>
</blockquote>

<hr>

<h3>Code 1:</h3>

<pre><code>&gt;&gt;&gt; x = 0
&gt;&gt;&gt; def foo():
...   print(x)
...   print(locals())
... 
&gt;&gt;&gt; foo()
0
{}
</code></pre>

<hr>

<h3>Code 2:</h3>

<pre><code>&gt;&gt;&gt; def bar():
...   x = 1
...   def foo():
...     print(x)
...     print(locals())
...   foo()
... 
&gt;&gt;&gt; bar()
1
{'x':1}
</code></pre>

<p><sub><strong>Free variables</strong> are returned by <code>locals()</code> when it is called in function blocks, but not in class blocks.</sub></p>

<hr>

<p>In <code>Code 1</code>, <code>x</code> is a <strong>global variable</strong>, and it's used but not defined in <code>foo()</code>.<br>
However it's not a <strong>free variable</strong>, because it's not returned by <code>locals()</code>.<br>
I think it's not what the doc said. Is there a technical definition for <strong>free variable</strong>?</p>
