Function Scope
區域與全域
name = 'Tom'
def hello1():
name = 'Mary'
print('in hello1(), name is ' + name)
def hello2():
print('in hello2(), name is ' + name)
def hello3():
global name
name = 'Mike'
print('in hello3(), name is ' + name)
hello1()
print('Outside of function, name is ' + name)
hello2()
print('Outside of function, name is ' + name)
hello3()
print('Outside of function, name is ' + name)變數的作用域
Last updated