liwya 发表于 2017-4-21 12:08:58

python全局变量

  初学python之:
  python的全局变量测试

def test1():
global line
line=20*30
return line
def test2():
print line/0.1
test1()
test2()
  结果为:6000.0
  
 可见:要在方法中共享全局变量,必须显式声明其为global,不然,他会默认是局部变量的。
页: [1]
查看完整版本: python全局变量