m in built-in namespace
def foo():
m=3
def bar():
print "bar func is",m
bar()
print "foo func is",m
foo()
#bar func is 3
#foo func is 3
"""
"""
m in the local namespace
def foo():
m=3
def bar():
m=5
print "bar func is",m
bar()
print "foo func is",m
foo()
#bar func is 5
#foo func is 3
"""
"""
#m in the global namespace
m=8
def foo():
m=3
def bar():
m=5
print "bar func is",m
bar()
print "foo func is",m
foo()
#bar func is 5
#foo func is 3
"""
python-变量的作用域
最新推荐文章于 2022-05-07 09:30:00 发布