装饰器
def myAdd(a,b):
return a+b
def mySubstract(a,b):
return a-b
def myMultiply(a,b):
return a*b
def myDivide(a,b):
return a/b
def show():
print("======开始======")
show()
print(myAdd(3,4))
show()
print(mySubstract(3,4))
show()
print(myMultiply(3,4))
show()
print(myDivide(3,4))
def myAdd(a,b):
print("======开始======")
return a+b
def mySubstract(a,b):
print("======开始======")
return a-b
def myMultiply(a,b):
print("======开始======")
return a*b
def myDivide(a,b):
print("======开始======")
return a/b
print(myAdd(3,4))
print(mySubstract(3,4))
print(myMultiply(3,4))
print(myDivide(3,4))
def show(fun,a,b):
print("======开始======")
x = fun(a,b)
print(x)
def myAdd(a,b):
return a+b
def mySubstract(a,b):
return a-b
def myMultiply(a,b):
return a*b
def myDivide(a,b):
return a/b
show(myAdd,3,4)
show(mySubstract,3,4)
show(myMultiply,3,4)
show(myDivide,3,4)
def show(function):
def temp(x,y):
print("======开始======")
z = function(x,y)
return z
return temp
def myAdd(a,b):
return a+b
def mySubstract(a,b):
return a-b
def myMultiply(a,b):
return a*b
def myDivide(a,b):
return a/b
myAdd = show(myAdd)
print(myAdd(3,4))
mySubstract = show(mySubstract)
print(mySubstract(3,4))
myMultiply = show(myMultiply)
print(myMultiply(3,4))
myDivide = show(myDivide)
print(myDivide(3,4))
def show(function):
def temp(x,y):
print("======开始======")
z = function(x,y)
return z
return temp
@show
def myAdd(a,b):
return a+b
@show
def mySubstract(a,b):
return a-b
@show
def myMultiply(a,b):
return a*b
@show
def myDivide(a,b):
return a/b
print(myAdd(3,4))
print(mySubstract(3,4))
print(myMultiply(3,4))
print(myDivide(3,4))
def fun(*args,**kwargs):
print(args,kwargs)
fun(1)
fun(6,张三=18343336666)
fun(6,7,8,李四=66)
fun(王五=99,赵六=88)
def show(function):
def temp(*args,**kwargs):
print("======开始======")
z = function(*args,**kwargs)
return z
return temp
@show
def myAdd(a,b):
return a+b
@show
def myAdd1(a,b,c):
return a+b+c
@show
def mySubstract(a,b):
return a-b
@show
def myMultiply(a,b):
return a*b
@show
def myDivide(a,b):
return a/b
print(myAdd(3,4))
print(myAdd1(3,4,5))
print(mySubstract(3,4))
print(myMultiply(3,4))
print(myDivide(3,4))
def show(function):
def temp(*args,**kwargs):
print("======开始======")
z = function(*args,**kwargs)
print(z)
return z
return temp
@show
def myAdd(a,b):
return a+b
@show
def myAdd1(a,b,c):
return a+b+c
@show
def mySubstract(a,b):
return a-b
@show
def myMultiply(a,b):
return a*b
@show
def myDivide(a,b):
return a/b
myAdd(3,4)
myAdd1(3,4,5)
mySubstract(3,4)
myMultiply(3,4)
myDivide(3,4)