给你写一小段代码。
import os,sys,time,traceback
global something_count_as_global #
something_count_as_global = 3 #init the value
def call_many_times():
global something_count_as_global #this declare is important
something_count_as_global +=1
def test():
global something_count_as_global
for i in range(10):
call_many_times()
print something_count_as_global #expected, 3, 4, 5, ...12
if __name__=="__main__":
test()
全局变量 不可以作为形参。也就是说 他不能被函数引用
可以参考一下这个网站的回答:网页链接