Python generate send () method (detailed description), python generate
I searched for it on the Internet. I thought it was hard to explain it for half a day. I 'd like to write it here.
Def generator (): while True: receive = yield 1 print ('extra '+ str (receive) g = generator () print (next (g) print (g. send (111) print (next (g ))
Output:
1extra1111extraNone1
Why? Click "send" to see a sentence.
Send: Resumes the generator and "sends" a value that becomes the result of the current yield-expression.
That is to sayHere yield 1 is regarded as an overall expression. The content you send will be used as the value of this expression. You can use anything on the left to receive or not receive it, in short, yield is the one you sent in. This expression is what you send in and then continues to execute. If you encounter yield again, output the expression following yield.
Of course, normally, no constant will be output, and a volume related to the received content will be output, otherwise it will not be sent in vain.
The above python generate send () method (detailed description) is all the content shared by the editor. I hope you can give us a reference and support the help house.