# 函式修飾器

``def friedchicken():    return 49.0print(friedchicken())  # 49.0``

``def sidedish1(meal):    return lambda: meal() + 30def friedchicken():    return 49.0friedchicken = sidedish1(friedchicken)print(friedchicken())    #   79.0``

sidedish1()接受函式物件，函式中使用lamdba建立一個函式物件，該函式物件執行傳入的函式取得主餐價格，再加上附餐價格，sidedish1()傳回所建立的函式物件給friedchicken參考，所以之後執行的friedchicken()，就會是主餐加附餐的價格。

``def sidedish1(meal):    return lambda: meal() + 30@sidedish1def friedchicken():    return 49.0print(friedchicken())    #   79.0``

@之後所接上的名稱，實際上就是個函式，@sidedish1這樣的標注方式，讓@sidedish1更像是個修飾器（Decorator），將friedchicken()函式加以修飾，增加附餐價格。

``def sidedish1(meal):    return lambda: meal() + 30    def sidedish2(meal):    return lambda: meal() + 40@sidedish1@sidedish2def friedchicken():    return 49.0print(friedchicken())   # 119.0``

``def sidedish1(meal):    return lambda: meal() + 30    def sidedish2(meal):    return lambda: meal() + 40def friedchicken():    return 49.0friedchicken = sidedish1(sidedish2(friedchicken))print(friedchicken())   # 119.0``

@deco('param')
def func():
pass

func = deco('param')(func)

``def sidedish(number):    return {        1 : lambda meal: (lambda: meal() + 30),        2 : lambda meal: (lambda: meal() + 40),        3 : lambda meal: (lambda: meal() + 50),        4 : lambda meal: (lambda: meal() + 60)    }.get(number, lambda meal: (lambda: meal()))@sidedish(2)@sidedish(3)def friedchicken():    return 49.0   print(friedchicken()) # 139.0``

``def sidedish(number):    def dish1(meal):        return lambda: meal() + 30            def dish2(meal):        return lambda: meal() + 40            def dish3(meal):        return lambda: meal() + 50            def dish4(meal):        return lambda: meal() + 60            def nodish(meal):        return lambda: meal()            return {        1 : dish1,        2 : dish2,        3 : dish3,        4 : dish4    }.get(number, nodish)@sidedish(2)@sidedish(3)def friedchicken():    return 49.0   print(friedchicken()) # 139.0``