2006年03月01日 星期三 10:03
你这里面的a是全局变量, inc是对全局的a进行操作,因为你在inc里面对a进行了定义global 如果你写成这样: a = 1 def inc(): a = 0 a += 3 那么inc调用的将是函数内部申明的a, 他的值将是3 taodev 2006-03-01 发件人: Peng Xiaoyu 发送时间: 2006-02-28 22:34:21 收件人: python-chinese at lists.python.cn 抄送: 主题: Re: [python-chinese] SOS 一个调用模块全局变量的问题 对于作用域我也不太清楚,比如下面的例子,a到底是属于那个作用域,inc是对哪个a操作 (~) pxy at equaker $ cat test.py a = 1 def inc(): global a a += 1 >>> from test import a >>> from test import inc >>> a 1 >>> inc() >>> a 1 >>> import test >>> a 1 >>> test.a 2 _______________________________________________ python-chinese Post: send python-chinese at lists.python.cn Subscribe: send subscribe to python-chinese-request at lists.python.cn Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060301/da5d31ea/attachment-0001.html
Zeuux © 2025
京ICP备05028076号