What is a Decorator?
Lesson 1 of 12 in Coddy's Python Decorators course.
A decorator is a way to modify or enhance the behavior of a function or class without modifying the original function or class itself. It is like wrapping a present with fancy paper, you are not changing the content, but you are adding something special to it.
In Python, decorators are functions that take another function as an argument and return a new function, which usually adds some new behavior to the original function. The new function is then used in place of the original function.
For example, you can use a decorator to log when a function is called or to authenticate the user before executing the function. By doing this, you can add functionality to a function without modifying its source code directly, making it more reusable and modular.
Let's Start!
Try it yourself
This lesson doesn't include a code challenge.