i have a question with this lines of code :
def first():
print('Hello From First')
def wrapper():
print('Hi From Second')
return wrapper
first()
# a = first()
# a()
Outpute:
Hello From First
when i call first() the inside Function not print but if i uncomment that 2 lines the output change to this :
Hello From First
Hello From First
Hi From Second
i wonder why assign function to variable and call that variable change the outpue?
thanks
'Hi From Second'is not printed in the first example? If so, it's because the functionwrapper()is never called. Simply defining a function does not make it run. In the second example,wrapper()is returned, saved to the variablea, and then called:a()runs the actual code and prints.firstreturns the functionwrapper; you assign that function toathen call it.