Python3.2官方文档翻译--作用域和命名空间实例
2014-04-28 01:24
721 查看
6.2.1 作用域和命名空间实例
下面的实例主要用来示范如何引用不同的作用域和命名空间,关键字global和nonlocalru如何影响变量绑定。实例运行结果是:
After local assignment: test spam
After nonlocal assignment: nonlocal spam
After global assignment: nonlocal spam
In global scope: global spam
注意局部赋值(这是默认的)不能改变scope_test方法中的spam的绑定值。但是nonlocal赋值可以改变它的值。全局变量赋值只能改变与模块同一级的值。
你可以看到在全局变量赋值前没有给spam绑定值。
相关文章推荐
- Python3.2官方文档翻译--作用域和命名空间实例
- Python3.2官方文档翻译--作用域和命名空间
- Python3.2官方文档翻译--作用域和命名空间
- Python3.2官方文档翻译--实例对象和方法对象
- Python3.2官方文档翻译--实例对象和方法对象
- 第36篇 翻译webrtc官方文档(三)及PHP命名空间(二)
- Python3.2官方文档翻译-标准库概览(二)
- Python3.2官方文档翻译--类备注和异常也是类
- Python3.2官方文档翻译--迭代器
- Python3.2官方文档翻译-列表工具和十进制浮点数计算
- Python3.2官方文档翻译--清理动作
- Python3.2官方文档翻译--继承
- Python3.2官方文档翻译--异常抛出和自定义异常
- 第35篇 翻译webrtc官方文档(二) 及word下载bug及php命名空间
- Python3.2官方文档翻译--输出格式化
- Python3.2官方文档翻译--迭代器
- Python3.2 官方文档翻译--错误与异常
- Python3.2官方文档翻译--异常抛出和自定义异常
- Python3.2官方文档翻译--类总介绍
- Python3.2官方文档翻译--异常处理