Python Full Stack development 10

Source: Internet
Author: User

        The step of the function
order : position parameter, dynamic receive location parameter *-> default value, dynamic receive keyword parameter * *
position parameter->*args-> default parameter value->**kwargs
I. Function parameters--Dynamic parameter transfer
  1. Dynamic Accept Position Parameters
Writing in the parameter position * means receiving any content
When you receive parameters dynamically, be aware that the dynamic parameter must be behind the position parameter
  2. Dynamic Receive keyword Parameters
Dynamic receive keyword parameter must be on the last side
Use * or * *in argument locations, they are used to break lists and strings
Two. namespaces, local namespaces, scopes, loading order
After the Python interpreter starts executing, it opens up a space in memory, and whenever a variable is encountered, the relationship between the variable name and the value is recorded, but when the function definition is encountered, the interpreter simply reads the function name into memory, indicating that the function exists, and that the variables and logic inside the function The interpreter is not concerned. That is, the function is just loaded in the beginning, and only then, when the function is called and accessed, the interpreter will open the variable's internal space according to the variables declared inside the function. As the function executes, the space occupied by the variables inside these functions is emptied as the function executes.

Classification of namespaces:
1. Global namespace --we directly in the py file, the variables declared outside the function belong to the global namespace
2. Local namespaces --variables declared in functions are placed in the local namespace
3. Built-in namespaces --store the Python interpreter's name, list, tuple, str, int these are built-in namespaces

Load Order:
1. Built-in namespaces
2. Global namespaces
3. Local namespaces
Order of Values:
1. Local namespaces
2. Global namespaces
3. Built-in namespaces
Scope : scope is the scope of action and is divided into global scope and local scope according to the effective scope

Global scope:

Contains built-in namespaces and global namespaces. Can be used anywhere in the entire event (follow the top-to-bottom row-by-line execution).
Local scope:

Can be used inside a function.

Scope namespaces:
1. Global scope: global namespace + built-in namespaces
2. Local scope: local namespaces

Functions: Globals () and locals ()
Globals (): variable and function information used to view global scopes
locals (): used to view the contents of a local scope (which layer it depends on, which layer of variables and function information)


3. Nesting of functions
1. Just meet () is a function call, if not () is not a function call
2. Order of execution of functions
4.gloabal,nonlocal keywords
Gloabal: Indicates that the variable is not locally created, but instead a global variable
Nonlocal: Represents a variable that calls a parent space in a local scope (cannot be called to a global variable, even if it has only one layer)

Python Full Stack development 10

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.