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()
5 Respostas
+ 2
Works fine on app version of sololearn ,web version has problems ,you can mail sololearn for the issue :-)
+ 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.
+ 1
Thanks Tibor Santa
0
def decor(func):
def wrap():
print("============")
func()
print("============")
return wrap
def print_text():
print("Hello world!")
decor(print_text)
0
This variations say no output in app version as well