A Python decorator is a design pattern that allows modify an existing function or method behavior without altering their actual code. Essentially, it’s a function that receives another function as argument an return a new function that enhances or modifies the original function’s behavior.
To define a decorator function just add the @decorator_name
syntax above the target function. This syntax is called syntactic sugar.
Example 1
Do something BEFORE the function call !
Hello World !
Do something AFTER the function call !
Example 2
Function cummulative_sum_to_n took 0.001065969467163086 seconds to run.
49995000