首页 > 编程语言 > 详细

Python yield用法

时间:2015-07-22 22:12:29      阅读:220      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!