Adorner:
1 Import Time2 defcal (L):3Start_time=time.time ()4res=05 forIinchL:6Time.sleep (0.1)7res+=I8Stop_time =time.time ()9 Print('the run time of the function is%s'% (stop_time-start_time))Ten returnRes One A Print(Cal (range (100)))View Code
Decorator preview:
1 Import Time2 defTimmer (func):3 defWrapper (*args,**Kwargs):4Start_time=time.time ()5Res=func (*args,**Kwargs)6Stop_time =time.time ()7 Print('function run time is%s'% (stop_time-start_time))8 returnRes9 returnwrapperTen @timmer One defcal (L): Ares=0 - forIinchL: -Time.sleep (0.1) theres+=I - returnRes - -Res=cal (Range (10)) + Print(RES)View Code
Higher order functions:
1. The parameter received by the function is a functional name
2. The return value of a function is a functional name
3. Any one of the above conditions can be called the higher order function
Python's Decorator