Python Full stack Python Foundation (ix) scoped function nesting closure

Source: Internet
Author: User

Namespaces and Scopes

variables, functions

Divided into three kinds

#内置名称空间 built-in functions,

System functions are internally customized.

Python view built-in functions, commands:

Import Builtins

Dir (builtins)

#全局名称空间 file is written in the head, there is no indentation defined function or variable.

Once defined, it can be used anywhere in the entire file.

#局部名称空间

Once defined, it can be called within a local environment, such as a variable defined in a defined function, which can only be called inside the current function, and cannot be called outside the global or other functions.

External, or other defined function calls, will be an error!

Built-in and global namespaces collectively known as Global scopes

A local namespace is called a local scope

#先定义后使用!!!

Use the search process: Local find this layer can not find the words, will go up a layer of defined function to find, can't find---> global find, global find words---> from the system's built-in search

Query global Globals () Local: Locals () output to dictionary format

X=1

def func ()

Print ("from Func")

x=2

Print (Globals ())

function nesting and static nesting fields

#嵌套调用

#嵌套定义

Function object and Closure

A function is the first class of objects.

Functions can be assigned values,

The function can be passed as a parameter,

Think of the function as the return value,

Consider a function as an element of a container type.

#闭包

Definition: must first be an internally defined function that contains a reference to an outer scope instead of a global domain name word.

No value will return to none.

Non-parametric adorner

Python Full stack Python Foundation (ix) scoped function nesting closure

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.