参考链接: Python中的装饰器
def itcast1(fun):
def inner(*args, **kwargs):
print("itcast1 start")
# args -> 元组数据()
#kwargs -> 字典数据{}
#result用来接收被装饰函数的返回值
result = fun(*args, **kwargs)
print("itcast1 end")
return result
return inner
@itcast1
def say_hello():
print("hello")
say_hello() # inner()
@itcast1
def add(num1, num2):
print(num1 num2)
add(100, 200) # inner(100, 200)
# 函数中如果没有使用return返回值,默认情况函数也是有返回值的,默认返回None
@itcast1
def minus(num1,num2):
return num1-num2
ret = minus(200,50) # ret = inner(200, 50)
print(ret)