Python function Learning

Source: Internet
Author: User

Unlike other languages, functions can also be invoked as arguments (called "Top Citizens" in the book) .

Match parameter Collection keyword more laughed at!

    • Functions can also be defined inside a function
    • An intrinsic function can be considered as a closure (a closure is a function that can be dynamically generated by another function, and can be changed and stored outside the value of a variable created by the function)???
    • Anonymous Harvey Lambda (), used instead of small functions, define the callback function???

Generator

This is definitely a super-good thing. Python has some of its own generator functions, such as range ()

You can also define your own generator function, where its return statement is completed by yield.

Decorative Device

Essence: Takes a function as input and returns another function.

Without affecting the source code, you can add some desired output. Common: Increase the basis of debug declarations to view incoming parameters

Such as: You can write a piece of code, the output source code contains functions, function parameters, as well as parameter invocation process, output and other information.

Usually use Python tips:

    • *args, **kwargs
    • Closed Package
    • function as a parameter

Alternatively, you can add the adorner name directly before the function to be decorated @decorator_name:

The same function can be performed by more than one adorner, the adorner near the function definition Def, and then up. But any order will be the same result. (Adorners will never change the original code.)

Python function Learning

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.