擅长:python、mysql、java
<p><a href="http://docs.python.org/reference/datamodel.html" rel="nofollow">language reference</a>指定<code>func_closure</code>是“一个包含函数自由变量绑定的单元格的元组。”</p>
<p>现在,请注意两个版本之间的区别:在第一个版本中,<code>i</code>是一个模块级(即全局)变量。评估每个函数的结果是相同的:</p>
<pre><code>>>> [f(2) for f in flist]
[4, 4, 4]
</code></pre>
<p>在每个函数中,<code>i</code>不是自由的,而是引用全局的<code>i</code>,因此不,输出不应该是非零长度元组的列表。在</p>
<p>实际上,您可能不关心<code>func_closure</code>的值,除非您在做一些相当深奥的魔术。如果您正在做一些神奇的事情,请注意,在给定规范的情况下,如果没有自由变量,<code>func_closure</code>不应该是空元组,那么如果您希望您的代码能够在甚至不同的python版本之间移植,那么就要适当地处理这种情况。在</p>