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的一些应用】具体的讲解
传送门
视频学习
推荐阅读
- 热闹中的孤独
- Shell-Bash变量与运算符
- JS中的各种宽高度定义及其应用
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 深入理解Go之generate
- 异地恋中,逐渐适应一个人到底意味着什么()
- 我眼中的佛系经纪人
- 《魔法科高中的劣等生》第26卷(Invasion篇)发售
- “成长”读书社群招募
- 2020-04-07vue中Axios的封装和API接口的管理