+ 1

Decorators

text = input() def uppercase_decorator(func): def wrapper(text): print(text.upper()) return wrapper @uppercase_decorator def display_text(text): return(text) print(display_text(text)) Why in the end "None"

28th Aug 2021, 8:25 PM
MiNt65
MiNt65 - avatar
1 Answer
+ 3
display_text(text) first calls the decorator function with function display_text as argument to it . Decorator returns the wrapper function . After that wrapper function is called with the argument that is passed from display_text function to it. wrapper function prints the uppercase value but doesn't returns anything . If it would have returned a value, using print(display_text(text)) would print that returned value but since no value is returned it prints None. Edit: The following is how the code works, a=uppercase_decorator(display_text) a(text) => prints uppercase value of text but since it returned nothing printing it out ( print(a(text)) ) will return None.
28th Aug 2021, 8:47 PM
Abhay
Abhay - avatar