Oi********oi********oi
The above * symbol represents a series of code, OI represents a "yield" keyword derived from the "data exchange, called Oi"
In a function that has a "yield":
In the "yield" where there is a "oi" process, why is not "IO", because it is the first "O" and "I".
"O" represents a value from generator.
"I" represents generator received a value from the outside world.
In general, you can use next or send in the outside world.
At first, generator stopped at the start of the function. Just like this ("" This symbol represents the location of the instruction execution):
"" **********oi*********oi**********oi
Then, for the first time, you must use next to get generator to the "O" position, that is to say, this time generator has sent a value.
However, this time the "I" has not been implemented. Just like this:
"O" I*********oi**********oi
If you continue to use next, you can, and you will get this:
oi********* "O" I**********oi
That is, your generator has reached the second "O" where the second value has been given, and at the time of the first "I" the generator has been sent to a None value. That is, using next can only send a None value to this generator.
This time, you change the send, for example gen.send (1). will become this:
oi*********oi********** "O" I
Your generator is parked in the third "O" place, notice that the "Third O" has been executed. And, you feed an integer value 1, notice that it is given a second "I".
Python generator Next Send