A Python decorator is a specific change that we make in Python syntax to alter functions easily. Decorators were added in Python 2.4 to make function and method wrapping (a function that receives a function and returns an enhanced one) easier to read and understand.
Function decorators: adjust the behavior of a preexisting function by hooking into its start-up and teardown mechanisms.
import functools def my_decorator(myfunc): @functools.wraps(myfunc) def function_myfunc(): print("In the decorator!") myfunc() print("After the decorator!") return function_myfunc @my_decorator def my_function(): print("I am the function!") my_function()