Python yield用法

时间:2015-07-22 22:12:29   收藏:0   阅读:220
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

  

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!