0

Why? :|

```def decor(func): def wrap(): print("============") func() print("============") return wrap def print_text(): print("Hello world!") decor(print_text)``` Why doesn't it work? we have to add empty parenthesis after decor(print_text) to get output. Why? decor is a function that takes function as it's arguments and everything is ok; so why () ? :|

25th Aug 2020, 5:01 PM
Parsa Karami
Parsa Karami - avatar
2 Respuestas
+ 4
Decor function returns a function. You need to store it and then call it. x = decor(print_text) x()
25th Aug 2020, 5:40 PM
Charitra
Charitra - avatar
+ 2
You are right but see the decor function properly, it returns wrap function to the decor function when called so now you need to call the actual wrap function as well to get output
25th Aug 2020, 5:05 PM
Abhay
Abhay - avatar