Python Decorators: A Simple Guide
1 What is a Decorator?
A decorator in Python is a function that modifies the behavior of another function. It adds extra functionality without changing the original function code.
2 Why Use Decorators?
Decorators help you:
- Reuse code
- Keep functions clean
- Add logging, timing, or access control
- Make your code more readable