Python|Python中Decorator的一些应用

Python中Decorator的一些应用

import timedef display(func):#decorator装饰器 def wrapper(): #包装 t1 = time.time() func() t2 = time.time() print(t2-t1) return wrapperdef jg(x): for i in range(2,x): if x % i == 0: return False return True @display#装饰器的语法糖 def prime(): for i in range(2,20): if jg(i): print(i)prime()

Python|Python中Decorator的一些应用
文章图片

【Python|Python中Decorator的一些应用】具体的讲解
传送门
视频学习

    推荐阅读