Understanding Decorators in Python
Decorators in python comes from the well known decorator design pattern. Decorators gives additional features to your regular functions in…
Understanding Decorators in Python

Decorators in python comes from the well known decorator design pattern. Decorators gives additional features to your regular functions in python. Let us look at an example below:
def my_decorator(my_func):
"""
A decorator function that wraps another function to print dashes
before and after its execution.
"""
def my_wrapper_function():
print("-----") # Print the top visual separator
my_func() # Execute the original function passed into the decorator
print("-----") # Print the bottom visual separator
return my_wrapper_function # Return the modified wrapper function
@my_decorator # Apply the decorator to the function below
def hello_func():
"""Prints a friendly greeting message."""
print("Hello!!!")
# Call the decorated function to see the wrapper in action
hello_func()
In the above block of code, we can see that a regular function my_decorator() takes another function my_func() as an argument, giving us a Higher Order function in python.
We can wrap that my_func() function with a wrapper function namely, my_wrapper_function, which is then ultimately returned.
We can use any regular python function like the hello_func() with this decorator function, giving special features to that particular regular function used.
메타데이터
- post_id
- aa8bc5161fb7
- slug
- understanding-decorators-in-python-aa8bc5161fb7
- url
- https://medium.com/@atmtahsin/understanding-decorators-in-python-aa8bc5161fb7
- canonical_url
- https://medium.com/@atmtahsin/understanding-decorators-in-python-aa8bc5161fb7
- author_url
- https://medium.com/@atmtahsin
- status
- ok
- fetched_at
- 2026-08-25 23:37:46