Found 1 Questions For function decorators in Python

How to make a chain of function decorators in Python?

Updated on 30-Jan-2023 19:39:21
Decorators are “wrappers”, which allow us to execute code before and after the function they decorate without modifying the function itself. Example The given code can be wrapped in a chain of decorators as follows. def makebold(fn): def wrapped(): return "" + fn() + "" return wrapped def makeitalic(fn): def wrapped(): return "" + fn() + "" return wrapped @makebold @makeitalic def hello(): return "hello world" print hello() Output C:/Users/codegyan/~.py hel... Read Mores



Advertisements

ads