Global and local变量的区别
脚本一:
str = '1'
print ('%15s = %s' %('original',str))
def test():
str = '0'
print ('%15s = %s' %('in function',str))
test()
执行结果:
original = 1
in function = 0
out function = 1
脚本二:
str = '1'
print ('%15s = %s' %('original',str))
def test():
global strstr = '0'
print ('%15s = %s' %('in function',str))
test()
执行结果:
original = 1in function = 0
out function = 0