返回顶部

收藏

yield statement: defining a generator function,

更多
def gensquares(N):
     for i in range(N):
         yield i ** 2               # resume here later

for i in gensquares(5):             # resume the function 
     print i, ':',                  # print last yielded value

x = gensquares(10)

print x.next()
print x.next()
print x.next()

标签:Python,Buildin,Function

收藏

0人收藏

支持

0

反对

0

发表评论