Decorator = higher order function + function nesting + closure

# #The list becomes an iterator 
# s=[1,2] 
# s.__iter__() 
# #iter(s) #Decorator 
: The essence is a function, and the function adds additional functions to other functions #Principle : 
# 
1 Do not modify the Source code of the decorated function 
# 2 Do not modify this decorated function 
# The following function is this function, but new functions need to be added 
# Decorator = higher-order function + function nesting + closure
import time
def cul(s):
# start_time=time.time()
res=0
for i in s:
time.sleep(0.1)
res+=i
# stop_time=time.time()
# print('程序运行时间%s'%(stop_time-start_time))
return res
# res=cul(range(10))
# print(res)
res=cul(range(10))
print(res)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325286052&siteId=291194637