The main topic of this lesson
- Scope Additions in Python
- Socketserver Source
- Homework this week
Scope Additions in Python
- There are no block-level scopes in the Python world .: cannot print name in java/c+ world.
# can't print name in java/c+ world. # but in the Python/javascript world, you can print name. if 1 = = 1: ... ' Janice ' Print(name) Janice
no block-level scope in Python (small knowledge point one) for in range: ... =print(name)9
no block-level scope in Python (small Knowledge Point II)
- But in the Python/javascript world you can print name. In Python, a function is used as the scope.
>>> del name >>> def Func (): ... name = " janice " ... >>> print <STDIN> Span style= "color: #800000;" > ", line 1, in <module>nameerror: Name name is not defined
in Python, a function is used as a scope (small knowledge point III)
- Python is a scoped chain, and for the scope, its scope has been determined before the function is executed, and the scope chain has been determined.
' Alex ' # This is F1 () is a scope, it is an internal scope def F1 (): ... Print # This is F2 () is scoped def F2 (): ... ' Eric ' ... >>> F2 () Alex
Python is a scoped chain (small knowledge point four)>>> name ='Alex'# This is F1 () is a scope, it is an internal scope>>>defF1 (): ...Print(name) ...#this is F2 () is a scope>>>defF2 (): ... name='Eric'... returnF1 ...>>> ret =F2 ()>>> ret ()#this is equivalent to running F1 ()Alex
Python is a scoped chain (small knowledge point five)
- for Loop, then add 1 to each element, and finally generate a list
# it executes a for loop, then adds 1 to each element, and finally generates a list forif x > 6]print(LI)
Python Lambda + for loop (small knowledge point six)>>> Li2 = [lambda for in range]>>> ret = li2[0] () Print (ret)9
Python Lambda + for loop (small knowledge point seven)>>> li = [] for in range: ... def F1 (x=i): ... return x ... ... Print (Li[0] ()) 0 Print (Li[1] ()) Print (Li[2] ())2
Python Lambda + for loop (small knowledge point eight)
Socketserver Source
I used IO multiplexing.
Multithreading, multiple layers, and processes
Homework this week
Day10 Job
References
Silver Horn King: the path to Python "seventh": threads, Processes, and co-routines
Golden Horn King:
The tenth chapter: Pythonの Network Programming advanced