Chicken soup:
First of all, I must cherish a grateful heart, thank the people in this world contact with me, whether you are concerned about me, is help, is indifferent, even disgust, I thank you.
Because care and help make me feel the hope of love,
Because indifference and disgust let me realize the cruelty of life,
Let the wrath of hate and the power of love into a force of eternal life, so that I continue to write a new chapter in this unknown path of life.
--run, little white.
application of the expression form of yield
Send (): has the effect of passing values and next . The position value is paused first , then next generator
Send (None): Indicates no value, only next effect, equivalent to direct next (), generally used for generator initialization operations.
Cases:
def foo (): print (' Start ') while True: x = yield print (' Value: ', x) g = foo () # Get generator print (G.send (None)) # G.send (None) is generally used for the initial generator. # It passes an empty value to the function, which is equivalent to directly executing the next (g) print ('---------------------------') print (G.send (1)) # First pass the number 1 to yield, Next (g) is executed, so the result of the print function return value is none. Print ('---------------------------') print (G.send (2)) # The number 2 is passed to yield, and then next (g), so the result of the printing function return value is none. Print ('---------------------------') print (Next (g))
Output Result:
startnone---------------------------1None---------------------------2 None---------------------------value:nonenone
View Code
Python Basics Application of expression form of--yield, process-oriented programming, built-in functions