您的位置:首页 > 编程语言 > Python开发

Python 之 使用全局变量

2010-09-27 16:37 127 查看
这里定义了两个全局的变量countx 和 county

#!/usr/bin/env python

#__metaclass__ = type

nest = [[1,2],[3,4],5]

countx = 0

county = 0

def flatten(nested):

try:

for sublist in nested:

print 'sublist=',sublist

# global countx

# print 'countx = %i' % countx

# countx += 1

for element in flatten(sublist):

print 'element=',element

# global county

# print 'county = %i' % county

# county += 1

yield element

except TypeError:

print 'except'

# print countx,county

yield nested
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: