Python generator Next Send

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.