• python学习


    def myYield2():
        for i in range(3):
            yield '2222 i am in myYield2', 'i = ', i
    
    
    def myYield():
        for i in range(10):
            yield '0000 i am in myYield', 'i = ', i
            for j in myYield2():
                yield '1111 i am in for myYield2', 'j = ', j
    
    f = myYield()
    print 'KKK', f.next()
    print 'KKK', f.next()
    print 'KKK', f.next()
    print 'KKK', f.next()
    print 'KKK', f.next()
    print 'KKK', f.next()
    print 'KKK', f.next()

    yield有一点像return, 返回的结果如下:

    KKK ('0000 i am in myYield', 'i = ', 0)
    KKK ('1111 i am in for myYield2', 'j = ', ('2222 i am in myYield2', 'i = ', 0))
    KKK ('1111 i am in for myYield2', 'j = ', ('2222 i am in myYield2', 'i = ', 1))
    KKK ('1111 i am in for myYield2', 'j = ', ('2222 i am in myYield2', 'i = ', 2))
    KKK ('0000 i am in myYield', 'i = ', 1)
    KKK ('1111 i am in for myYield2', 'j = ', ('2222 i am in myYield2', 'i = ', 0))
    KKK ('1111 i am in for myYield2', 'j = ', ('2222 i am in myYield2', 'i = ', 1))
  • 相关阅读:
    delphi多线程加锁
    delphi中pchar、char、string的定义与区别
    delphi指针
    关于delphi函数的调用顺序问题
    easyexcel
    # springcloud-eureka-feign-mybatis-seata ### 整合步奏
    zuul网关
    ## feign远程调用开启熔断
    eureka2
    Eureka
  • 原文地址:https://www.cnblogs.com/zhang-pengcheng/p/4680991.html
Copyright © 2020-2023  润新知