zoukankan      html  css  js  c++  java
  • Python yield用法

    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

      

  • 相关阅读:
    装饰者模式
    代理模式
    享元模式
    模板模式
    命令模式
    建造者模式
    单例模式
    观察者模式
    迭代器模式
    访问者模式
  • 原文地址:https://www.cnblogs.com/yicaifeitian/p/4668724.html
Copyright © 2011-2022 走看看