python全局变量

初学python之:

python的全局变量测试

 

 

def test1():
	global line
	line=20*30
	return line
def test2():
	print line/0.1
test1()
test2()

  结果为:6000.0

 可见:要在方法中共享全局变量,必须显式声明其为global,不然,他会默认是局部变量的。

posted @ 2012-12-14 12:01  niewj  阅读(141)  评论(0编辑  收藏  举报