SyntaxStudy
Sign Up
Python Stacking Multiple Decorators
Python Intermediate 3 min read

Stacking Multiple Decorators

Stacking Decorators

You can stack multiple decorators on one function. They apply bottom-up: the closest decorator to the function is applied first.

Example
def bold(func):
    def wrapper():
        return "<b>" + func() + "</b>"
    return wrapper

def italic(func):
    def wrapper():
        return "<i>" + func() + "</i>"
    return wrapper

@bold
@italic
def text():
    return "Hello"

print(text())  # <b><i>Hello</i></b>
Pro Tip

Decorators stack outer-to-inner top-to-bottom: @bold applies after @italic.