Python Learning notes-closures

Source: Internet
Author: User
1 definitions

Definition: In computer science, closures are abbreviations for lexical closures and are functions that reference free variables.

Simply put: A closure is a function that reads the internal variables of other functions, and a closure is a bridge that connects the inside of the function to the outside of the function. --Source Baidu Encyclopedia

2 description

Conditions for the formation of closures:

1. Closures must have intrinsic functions

2. The variable of the outer function must be referenced in the intrinsic function, that is, the free variable

3. The outer function must say that the inner layer function returns

Advantages:

1. Extended the life cycle of local variables

2. Enhanced Encapsulation

Disadvantages:

1. Increased memory burden

2. Intrinsic functions can modify the external function variables, prone to error modification

Python Learning notes-closures

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.