Just looked it up online,It feels like speaking for a long time is not clear,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))
1 extra111 1 extranone 1
Why is this so,Click into 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 treated as an expression,The content of your send will be used as the value of this expression,Whatever you use on the left to receive or not to receive,In short yield is the thing you send in.This expression becomes the thing after you send in and continues to execute,When yield is encountered again, the expression following yield is output.
Of course, if you usually use it, it will not output a constant.Will output a quantity related to what was received,Otherwise, it was not sent for nothing.
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file