初学python之:
python的全局变量测试
def test1(): global line line=20*30 return line def test2(): print line/0.1 test1() test2()
结果为:6000.0
可见:要在方法中共享全局变量,必须显式声明其为global,不然,他会默认是局部变量的。