码迷,mamicode.com
首页 > 编程语言 > 详细

Python yield用法

时间:2015-07-22 22:14:08      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

yield 官方称是一种生成器,每每遇到这样包含这个关键字的代码,往往有些难读。
def testyield(count): for x in xrange(count): print "testyield" yield testinner(x) def testinner(count): for x in xrange(count): print "testinner" yield x testyield(10) #执行程序,不输出任何东西 for x in testyield(10): #执行程序,不输出testinner(count)方法内容 print x for x in testyield(10): #执行程序,输出testinner(count)方法内容 for i in x: print i

  

Python yield用法

标签:

原文地址:http://www.cnblogs.com/yicaifeitian/p/4668724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!