Syntax such as Python builder

Source: Internet
Author: User

 Generator

The call to the generator function returns an object that is the generator (the type () function can be used to judge the object), and then the next () method can be used to obtain a sequence from the object.

The value passed to yield is returned by the next () method.

The next () method pauses the execution of the function when it encounters yield and returns. The execution of the restore function is called next again. You can print information to illustrate the execution of the generator.

def countdown (n):    print '---------1 ' while    n > 0:        print '---------2 '        yield n        print '---------3 '        N-= 1        print '---------4 '        

Call the generator and see how it works:

c = Countdown (5) C.next () C.next () C.next ()

Co-process

The general function only processes a single set of input parameters, and the co-process processes the input parameters that are sent to it. The co-process is created by the yield statement.

Syntax such as Python builder

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.