The application of the expression form of the Python Foundation Day--yield, process-oriented programming, built-in functions

Source: Internet
Author: User

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

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.