擅长:python、mysql、java
<p>啊,但是函数中的<code>id(x)</code>调用引用了传递给函数的全局x,但是<code>x = 2</code>创建了一个新的局部x。请尝试以下操作:</p>
<pre><code>def func(x):
print "inside function", id(x)
x = 2
print "still inside function", id(x)
x = 50
print "outside function" , id(x)
print 'Value of x before function call is', x
func(x)
print 'Value of x after function call is', x
</code></pre>
<p><strong>典型输出</p>
<pre><code>outside function 168950596
Value of x before function call is 50
inside function 168950596
still inside function 168951172
Value of x after function call is 50
</code></pre>