首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python的作用域有关问题

2012-03-17 
python的作用域问题Python code def func():t.start()# 为什么在函数内部可以使用定义在函数外面的对象

python的作用域问题

Python code
>>> def func():    t.start()    # 为什么在函数内部可以使用定义在函数外面的对象t?    for i in range(5):        print(i)        >>> t = Mythread(2)    <-- t是在函数外面定义的>>> func()01234>>> 2


[解决办法]
python变量作用域遵循一个称为LGB的规则,
This is the so-called LGB rule of name resolution: local, then global, then built-in.


请参考:
http://www.magicalboy.com/python-scope-legb.html

http://www.manaware.net/language-processing/variable-scope.html

热点排行