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
本文标题:Sth about Python 07 ---functions
本文链接:https://www.haomeiwen.com/subject/fwprqttx.html
网友评论