yield to achieve state save

import time
def func():
    print(123)
    sum = 0
    print(6666)
    yield sum
    print(7777)
    yield sum
    print(8888)
    yield sum

def fff():
    G = FUNC ()
     Print ( ' which is a function ffff ' )
     Print (Next (G))
    the time.sleep ( . 1 )
     Print ( ' which is a function ffff ' )
     Print (Next (G))
    the time.sleep ( . 1 )
     Print ( ' which is a function ffff ' )
     Print (Next (G))

fff()


# G = func () # func not executed at this function, must meet the following code next (g) before executing a function, and each of the next (g) only after the first cycle, the program will stop while 1: before waiting for the next next (G) 
# Print ( 'ABC') 
# the time.sleep (10) 
# Print (next (G)) 
# the time.sleep (10) 
# fff () # fff used in the next function ( g) that the program FFF () and FUNC () alternately performed 
# the time.sleep (10) 
# Print (Next (g))

 

Guess you like

Origin www.cnblogs.com/god-for-speed/p/11719110.html