![]() ![]() Print( "Something is happening after the function is called.", value) We can use a decorator to calculate and print the execution time of functions.ĭecorator for function with return value: def my_decorator( function): def wrapper(): We can use a decorator to add logs before and after the execution of functions. We will use the 2nd method in upcoming examples as it’s more readable. There are mainly two ways we can use the above decorator. In this example, this decorator is changing the function's behavior by doing extra stuff before and after the function call. Print( "Something is happening after the function is called.") Print( "Something is happening before the function is called.") ![]() Put simply: Decorators wrap a function, modifying its behavior.Ī simple decorator example: def my_decorator( function): def wrapper():
0 Comments
Leave a Reply. |