Decorators
Learn how to use decorators to modify or extend functions.
1
Introduction to Decorators
Decorators are a powerful feature in Python that allow you to modify the behavior of functions or methods. They are often used to add functionality to functions without modifying their code.
In this lesson, you’ll learn what decorators are, how to use them, and how to create your own decorators.

2
What Is a Decorator?
A decorator is a function that takes another function as input and returns a new function with added functionality. It’s often used with the @decorator_name syntax.
# Basic example of a decorator
def decorator(func):
def wrapper():
print("Before the function call")
func()
print("After the function call")
return wrapper
@decorator
def say_hello():
print("Hello!")
say_hello()