python可以在本地范围内声明全局变量吗?

tha*_*ote 0 python scope

python可以在本地范围内声明全局变量吗?

有用:

def main():
    # do some... for files varible
    for file in files:
       result = func(file)
    print result
Run Code Online (Sandbox Code Playgroud)

我无法理解.有人告诉我为什么result可以在for循环外看到.

谢谢.

Ign*_*ams 6

for语句不会启动新范围.只有模块,类声明和函数定义才能启动新范围.