0

Why is "return wrap" here? Python

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

5th Jun 2020, 1:00 PM
3.14
3.14 - avatar
2 Answers
+ 1
The function is returning the function wrap. When you assign decor(print_text) to 'decorator', 'decorator' has value wrap. As 'decorator' has a function as you can call it.
5th Jun 2020, 1:08 PM
XXX
XXX - avatar