python programming entry notes

First, the scope

In the python, the scope is divided into two types: global and local scope scope.

 Global scope is defined in the file level variables, function names. And local scope , the internal function is defined.

 About scope, we need to understand two things:

    a. In the global not have access to a locally defined variables

    b. In the local variables to access the global variable defined, but can not modify globally defined (Method of course be modified)

 

Example 1:

. 1 = X
DEF funx ():
    X = 10
    Print (X) 10 # printed out

funx ()
Print (X) to print out # 1

 

Example 2:

1 = X
DEF funx ():
    Print (X) to print out # 1

funx ()
Print (X) to print out # 1

 

Therefore, on the issue of scope, only need to remember two things on the line:

Global variables can be referenced anywhere in the file, but can only be modified to operate in the global; if desired local variable is not found, it will be to find out, will not find the error.

 

Second, advanced functions

Distinguish three general methods, static methods, dynamic method

Four, re library

 

Guess you like

Origin www.cnblogs.com/felix-g/p/11388082.html