can somebody explain difference in these two almost similar codes?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can somebody explain difference in these two almost similar codes??

Original code: https://code.sololearn.com/391/#py 1st variation: - why no output. def decor(func): def wrap(): print("============") func() print("============") return wrap def print_text(): print("Hello world!") decor(print_text) 2nd variation: def wrap(func): print("============") func() print("============") return wrap def print_text(): print("Hello world!") s=wrap(print_text) s()

7th May 2020, 9:45 AM
NITIN MAHESHWARI
NITIN MAHESHWARI - avatar
5 Answers
+ 2
Works fine on app version of sololearn ,web version has problems ,you can mail sololearn for the issue :-)
7th May 2020, 9:51 AM
Abhay
Abhay - avatar
+ 2
This is an excellent article on decorators that explains the whole concept starting from the basics. https://realpython.com/primer-on-JUMP_LINK__&&__python__&&__JUMP_LINK-decorators Highly recommended. Very long, so take your time with it. But totally worth reading.
7th May 2020, 10:13 AM
Tibor Santa
Tibor Santa - avatar
+ 1
7th May 2020, 10:23 AM
NITIN MAHESHWARI
NITIN MAHESHWARI - avatar
0
def decor(func): def wrap(): print("============") func() print("============") return wrap def print_text(): print("Hello world!") decor(print_text)
7th May 2020, 10:03 AM
NITIN MAHESHWARI
NITIN MAHESHWARI - avatar
0
This variations say no output in app version as well
7th May 2020, 10:03 AM
NITIN MAHESHWARI
NITIN MAHESHWARI - avatar