分类
技術分析

外匯投資的10個小技巧

Ikinuwento ni Juancho Trivino na palagi 外匯投資的10個小技巧 niyang kinakausap si Joyce Pring sa social media noon kahit madalas na ma-seen-zone ang messages niya.

Simple Sidebar

The starting state of the menu will appear collapsed on smaller screens, and will appear non-collapsed on larger 外匯投資的10個小技巧 screens. When toggled using the button below, the menu will change.

Make sure to keep all page content within the #page-content-wrapper . The top navbar is optional, and just for demonstration. Just create an element with the #sidebarToggle ID which will toggle the menu when clicked.

Python facing objects: closures

According to 外匯投資的10個小技巧 the literal meaning , A closure can be vividly understood as a closed package . This package is a function . In essence , Closures 外匯投資的10個小技巧 are bridges that connect functions inside and outside , In an internal function , References to variables in an external scope ,( And generally, 外匯投資的10個小技巧 the return value of external function is internal function ), So internal functions are considered closures . Closures don't just exist in Python 外匯投資的10個小技巧 in .

1.1 Generate a closure

In the above code , When a function 外匯投資的10個小技巧 is called fun() And then there's a closure inner_func(), And the closure has free variables “name”. Indicates when the function 外匯投資的10個小技巧 外匯投資的10個小技巧 func() After the end of the life cycle of , Variable name Will still exist , Because it's referenced by closures , All will not be recycled

1.1.2 Scope :

外匯投資的10個小技巧 Local scope : function , class

Global scope : modular , Or use. In code blocks global Keyword defined variables

Namespaces are created at 外匯投資的10個小技巧 外匯投資的10個小技巧 different times , Have different survival periods . The 外匯投資的10個小技巧 namespace containing the built-in name is in 外匯投資的10個小技巧 Python Created when the interpreter starts , It will never be deleted . The global namespace of a module is created when the module definition is read in ; Usually , The module 外匯投資的10個小技巧 外匯投資的10個小技巧 namespace will also persist until the interpreter exits . The local namespace of a function is created when the function is called , And is removed when the function returns or throws an error that is not handled within the function . Each recursive call has its own local Namespace ( Built in namespace 、 The module namespace 外匯投資的10個小技巧 and the local namespace of the function ).

1.1.3 Relationship between scope and 外匯投資的10個小技巧 namespace

One Scope Is a namespace directly accessible Python The text area of the program .外匯投資的10個小技巧

At any time during execution , There will be 3 or 4 A nested scope 外匯投資的10個小技巧 whose namespace can be accessed directly :

The most internal scope searched first contains the local name ( Inside the code block )

Search from the most recent closed scope The scope of any closed function of contains a nonlocal name , It also includes closed areas with non global names closest to each other : Upper layer code block

The penultimate scope contains the global name of the current module

Variables defined in the module
The outermost scope ( At last, the search ) Is a namespace with built-in names
python Built in namespace
Unqualified references try to find names in namespaces

Execution results :

1.1.4Python Binding operations in :

The formal parameter of the function
import Statement
Definitions of classes and functions
Assignment operation
for Cyclic header
Relevant assignment variables in exception capture

The binding operation is visible , Reference operations are available . Before quoting , There must be binding operations

data = 3
def test_func(arg1):
print(arg1)
print(data)

test_func(4)
Search for :
Function area :
arg1 The formal parameter of the function , There are binding operations , So it's visible
data Function area , No, data Binding operation 外匯投資的10個小技巧 of , So it's invisible
Go to the enclosed area on the upper floor to find , Because the enclosed area on the upper floor , So we can't find it
Go to the module area to find : data = 3 Bind operation , The module is visible in this area

To use the :
print(arg1) Between now and then I've been right arg1 Binding operation , test_func(4) => arg1=4
print(data) Before data Belongs to the module area , data = 3 Binding operation

1.2 Use of closures

Closure :

Is a nested function : outer, inner
The inner function references the variables of the outer function ( Free variable )
Return the inner function as the return value to the outer function
The execution environment is saved :inner-> quote data, hold inner Return as return value outer
inner Now is our execution environment