擅长:python、mysql、java
<p>有一种简单的检查方法:</p>
<pre><code>>>> def count_top_rt(tweet_set):
... print(id(tweet_set))
... for tweet in tweet_set:
... print(tweet)
>>> tweet_set = ["Sydney", "London", "Paris"]
>>> count_top_rt(tweet_set)
1951490534472
Sydney
London
Paris
>>> id(tweet_set)
1951490534472
>>> tweet_set2 = ["Sydney", "London", "Paris"]
>>> count_top_rt(tweet_set2)
1951490565832
Sydney
London
Paris
>>> id(tweet_set2)
1951490565832
</code></pre>
<p>如您所见,当一个变量作为变量传递时,无论全局变量的名称是什么,局部变量都将成为它的<code>reference</code>。这是因为解释器首先去局部变量堆栈检查变量(它是引用的原因是因为函数的参数行为),然后才引用全局变量。在</p>