Decorators
suggest changeIntroduction
Decorator functions are software design patterns. They dynamically alter the functionality of a function, method, or class without having to directly use subclasses or change the source code of the decorated function. When used correctly, decorators can become powerful tools in the development process. This topic covers implementation and applications of decorator functions in Python.
Syntax
def decorator_function(f): pass
# defines a decorator named decorator_function@decorator_function
def decorated_function(): pass
# the function is now wrapped (decorated by) decorator_functiondecorated_function = decorator_function(decorated_function)
# this is equivalent to using the syntactic sugar@decorator_function
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents