1.局部变量和全局变量的作用域
x = 1
def func():
x = 2
print x
func()
print x
输出:2
1
x = 1
def func():
x = 2
print x
输出:1
x = 1
def func():
global x
x = 2
print x
func()
print x
输出:2
2
1.局部变量和全局变量的作用域
x = 1
def func():
x = 2
print x
func()
print x
输出:2
1
x = 1
def func():
x = 2
print x
输出:1
x = 1
def func():
global x
x = 2
print x
func()
print x
输出:2
2