time (func): (*args**kwargs): start = time.time() result = func(*args**kwargs) end = time.time() (end-start) result infunc CaheDecorator(): __cache={} (func): .func = func (*args**kwargs): .func.CaheDecorator.__cache: CaheDecorator.__cache[.func.] : result = .func(*args**kwargs) CaheDecorator.__cache[.func.] = result (.__cache) result (): () time.sleep() () __name__ == : r1 = func1_long_time() r2 = func1_long_time() (r1) (r2)
这段代码他的运行顺序是怎么样的?
#时间模块 import time #sys系统模块 import sys time.clock() list1 = [x for x in range(2,10001,2)] costTime = time.clock() print('创建列表耗时:%g'%costTime)
老师,您好。我的代码是在按照视频上敲的,但有个问题,如下图,可怎么解决呀?
老师请问一下是因为最终log里面return了with_logging所以test.__name__打印的是with_logging的名字,可以这样去理解吗?谢谢老师
老师,为什么在这里会设有三个返回值呢,设置返回值的意义是什么啊,不是太清楚
老师,这个方法,只限定了最小必须匹配8位,如果输入20位以上,不会报None
#encoding=utf-8 import time def cost_time(func): def infunc(*args,**kwargs): start = time.time() result = func(*args,**kwargs) end = time.time() print(f"耗时:{end-start}") return result return infunc class CaheDecorator(): __cache={} #类属性,用作所有实例的共享缓存 def __init__ (self ,func): self.func = func def __call__ (self, *args, **kwargs): #如果缓存中有对应的方法名,则直接返回对应的返回值 if self.func.__name__ in CaheDecorator.__cache: return CaheDecorator.__cache[self.func.__name__] # 如果缓存中没有对应的方法名,则进行计算,并将结果缓存 else: result = self.func(*args,**kwargs) CaheDecorator.__cache[self.func.__name__] = result print(self.__cache) return result @cost_time #func1_long_time = cost_time(func1_long_time) @CaheDecorator #func1_long_time=CaheDecorator(func1_long_time) def func1_long_time(): """模拟耗时较长,每次执行返回结果都一样的情况""" print("start func1") time.sleep(3) print("end func1") return 999 if __name__ == '__main__': r1 = func1_long_time() r2 = func1_long_time() print(r1) print(r2)
这段代码的运行顺序是怎么样的?
reduce和map的区别在哪,两个好像都差不多
老师函数里面已经有a=10了,函数外面为什么还要加一个呢?我搞不明白,外面的有什么用
老师这段代码,在n=2时为啥不会打印呢??????
nonlocal a 在这里起什么作用 为什么要申明a 不是本地变量
正常情况的函数是不是变量用完就不能再用了,也就是说闭包的最大特点是变量用完还能用吗?
老师,str1 = re.sub(pattern,replace,s),中,为啥,会把s自动传给replace函数?是re.sub中定义的吗?
1、请编写一个正则表达式,要求能把以下这四种格式字符串:“$200.49”、“$1,999.00”、“$99”、“50.00美元”从一段文本中匹配出来。(不需要考虑千分位及小数点的位置校验)
2、【字符串处理】在上一题的基础上,试能把数字从字符串中提取出来。要求考虑欧元及人民币/美元的不同的千位分隔符的不同。示例:
EUR 1.409,00 => 1409 € 409,05 => 409.05¥409.50 => 409.5CNY 1,000 => 1000
老师能不能帮我写一下这个题,我最近刷题不太会
那老师 map和reduce函数返回值有啥不同 为啥一个返回需要list()一个可以直接打印
yield i 程序挂起 等待下面的a.__next__()执行,然后把i的值给了a.__next__(),然后继续执行temp =,这个时候为什么给temp赋不到值了
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637