+ 1
Can anyone explain this code ?? đ„ș
def decor(func): def wrap(): print("============") func() print("============") return wrap def print_text(): print("Hello world!") decorated = decor(print_text) decorated()
2 Answers
+ 1
decor function need a function as parameter.It has an inner function called wrap which alter the function used as param to its parent function then return the altered copie of the given function(here it was print_text).
When calling the decor function with print_text as parameter we create a variable decorated to store the result.Because the return type of decor is function so we call the function decorated().
0
Explanation is there...
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2463/
It is a way of logic to make declarations to some text or an output...
decor function return a wrap() function by including passed argument function fun() between a decorations.. So you can only 1 function..