1. Decorative Device
1.1 Definition:
essentially a function that decorates other functions-that is, adding additional functionality to other functions
1.2 Adorner principle:
1) cannot modify the source code of the decorated function;
2) cannot modify the calling mode of the decorated function;
1.3 Implement the Adorner knowledge Reserve:
The 1.3.1 function is the "variable"
Defining a function is equivalent to assigning a function body to a functional name.
1.3.2 Higher order functions
See the previous study notes
1.3.3 Nested Functions
Definition: Use DEF to declare a new function in a function body
# def foo (): #定义函数foo () ... m=3 #定义变量m =3; ... def bar (): #在foo内定义函数bar () n=4 #定义局部变量n =4 ... print (m+n) #m相当于函数bar () global variables ... bar ( ) #foo () function call function Bar () # foo () #调用foo () function 7
1.3.4 Decorator
Higher order function + nested function = = Adorner
- Fixed function parameters
# import time# def timer (func): ... def deco (name): ... start_time = Time.time () ... func (name) ... Stop_time = Time.time () ... print ("The Func Run time is%s"% (stop_time-start_time)) ... return deco# @timer # def Test (name): ... time.sleep (3) ... print ("In the test!--%s"% name) # test (' CC ')
- Function parameters are not fixed
2. Iterators & Generators
2.1 List-generated
2.2 iterators
2.3 Generators
3.json&pickle serialization of data
4. Program Catalog Specification
Python Learning Notes-(eight) decorators, generators & iterators