专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Perl/Python

python的作用域有关问题

发布时间:2011-06-29 20:10:41 文章来源:www.iduyao.cn 采编人员:星星草
python的作用域问题

Python code

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

        
>>> t = Mythread(2)    <-- t是在函数外面定义的
>>> func()
0
1
2
3
4
>>> 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
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: