0

Why does error occur??

In this code, def decor(func): def wrap(): print("============") func() print("============") return wrap def print_text(): print("Hello world!") print_text = decor(print_text) print_text() If I replace decor (print_text) with decor(print_text()) it gives error why?(after all we are calling function print_text.

20th Jun 2019, 5:50 PM
Akash
Akash - avatar
1 Réponse
0
Having the () after it indicates that you pass in the result of the function. Think of it as if that gets replaced by its return statement. Since the print function has no return, you get an error passing in null instead of a function
20th Jun 2019, 7:13 PM
Jackson O’Donnell