python函数问题求解答
这里面的func()什么作用 与下面函数中的funB()有什么区别import time
def time_master(func):
def call_func():
print("开始运行程序...")
start = time.time()
func()
stop = time.time()
print("结束程序运行...")
print(f"一共耗费了 {(stop-start):.2f} 秒。")
return call_func
@time_master
def myfunc():
time.sleep(2)
print("I love FishC.")
myfunc()
>>> def funA():
... x = 520
... def funB():
... x = 880
... print("In funB, x =", x)
... funB()
... print("In funA, x =", x)
...
>>> funA()
In funB, x = 880
In funA, x = 520 func 不是传进去的参数吗 这个参数应该是一个函数地址
所以func() 就是函数调用 @time_master
def myfunc():
time.sleep(2)
print("I love FishC.")
#@time_master相当于time_master(myfunc)
页:
[1]