Exploring Python Decorators
Published on: 2024-02-25 09:13:29
python
decorators
functions
Decorators in Python are a powerful feature that allows you to modify the behavior of functions or methods. Here's an example of a simple decorator:
def my_decorator(func):
def wrapper():
print("Before function.")
func()
print("After function.")
return wrapper
Decorators wrap a function, adding pre- or post-execution logic while keeping the original function intact, making your code more modular and reusable.