def hi():
return "hi yasoob!"
def doSomethingBeforeHi(func):
print("I am doing some boring work before executing hi()")
print(func())
doSomethingBeforeHi(hi)
#outputs:I am doing some boring work before executing hi()
# hi yasoob!
現(xiàn)在你已經(jīng)具備所有必需知識(shí),來進(jìn)一步學(xué)習(xí)裝飾器真正是什么了。裝飾器讓你在一個(gè)函數(shù)的前后去執(zhí)行代碼。