Content directory:
- Python scope
- The multiple inheritance differences between python2.7 and python3.5
- IO multiplexing
- Multithreading, process, and co-processes
Python scope
No block-level scopes in Python
If 1 = = 1: name = ' Jabe ' print (name) #可以正常输出jabe # no block-scoped scope in Python # is not used in C # or Java, prompt for name undefined
Function-scoped in Python
def func (): name = ' Jbae ' func () print (name) #会提示name为定义的报错, indicating that a function is scoped in Python
Python scope chain from inside to look out, until the error is not found
name = ' Jabe ' def F1 (): # name = ' a ' def f2 (): # name = ' B ' print (name) F2 () F1 () #输出jabe
The scope (chain) has been determined before the function is executed
name = ' Jabe ' def F1 (): print (name) def f2 (): name = ' LJB ' F1 () f2 () Output: jabe#=============================== name = ' Jabe ' def F1 (): print (name) def f2 (): name = ' LJB ' return f1ret = F2 () ret () output: Jabe
Lambda function scope
Li = [lambda:x for x in range]]r = li[0] () print (r) print (' =================== ') #输出为9, the example above is equivalent to the following code Li = []for i in range] (Ten): def F1 (): return i li.append (F1)
#li as a list, the inner element is the function of the same function
Print (Li[0] ()) print (Li[1] ()) print (Li[2] ()) print (Li[3] ()) #输出: # 9# ===================# 9# 9# 9# 9
Since the function is not executed when it is invoked, when the loop ends I is 9 and the last call is 9
The above function can be printed with a slight change of 9.
Li = []for i in range: def F1 (x=i): return x li.append (F1) #li as list, inner element is the same function as function print (Li[0] ()) Print (li[ 1] ()) print (Li[2] ()) print (Li[3] ()) #输出: # 0# # 3
In the above example, the I value is assigned to x because each loop is executed, so the print is 0,1,2,3
The multiple inheritance differences between python2.7 and python3.5
We know from the knowledge we have learned that the multiple inheritance order of the python3.5 class is inherited from left to right and from bottom to top.
In python2.7, if the order for the new class and the py3.5 is the same, the inheritance order of the classic class is slightly different, and the search is deep, until it is found, not to the right.
Do not inherit object is a classic class, inheriting object is a new class (consistent with Py3)
IO multiplexing
Multithreading, process, and co-processes
Python devops Development (10)----IO multiplexing multithreading, process, and coprocessor