0

can anyone help me to understand this code and the concept behind this

def decor(func): def wrap(): print("============") func() print("============") return wrap def print_text(): print("Hello world!") decorated = decor(print_text) decorated()

13th Feb 2021, 1:39 PM
Rahul Prasad
Rahul Prasad - avatar
1 Answer
+ 2
decor(func) is a function... that takes a function as a parameter. You can also reference a function without calling it by omitting the "()" after the function name. All decor does is: 1.print some equal signs, 2.call the function given as a parameter (using "()"), 3.print some more equal signs. when you look at the function print_text(), it just prints Hello World. So when plugged in to the above function it goes: 1.print equal signs, 2.print Hello World, 3.print more equal signs
13th Feb 2021, 2:36 PM
Slick
Slick - avatar