python 装饰器 decorator
import time def deco(fun): def wrapper(): t1=time.time() res=fun() t2=time.time() print("total time is: {:.4} s".format(t2-t1)) return res return wrapper def is_prime(num): if(num==1): return 0 elif(num==2): return 0 else: for i in range(2,num): if(num%i==0): return 0 return 1 @deco def count_nums(): count=0 for i in range(2,1001): if(is_prime(i)): count+=1 return count count=count_nums() print(count)
坑 明天在补
如果你够坚强够勇敢,你就能驾驭他们