0

How the inner function is executing in this scenario

When I give return Inner statement, how the Inner function is executing ? I didn't give Inner(), I just gave Inner . https://code.sololearn.com/ctcgHUr08B24/?ref=app

30th Aug 2022, 5:55 AM
Levi
Levi - avatar
4 Respostas
+ 1
Levi @decor is work like this if you don't write @decor on above the function def decor(func): def inner(): print('hello from inner') return inner #@decor def display(): print('Hello') #display() r_print = decor(display) r_print() ------------you can understand by this example------ def abc(func): def Inner(): print('hello from inner') return Inner @abc def display(): print('Hello') display() see I have changed function name here 'abc' and written @abc on above the function display() it means display() function internally call abc function and print statement of abc function
30th Aug 2022, 6:40 AM
A͢J
A͢J - avatar
0
A͢J what is r_print()
30th Aug 2022, 7:26 AM
Levi
Levi - avatar
0
A͢J I can understand ur answer, But in return Inner How the Inner function is executing ? It should be return Inner() right !?
30th Aug 2022, 7:35 AM
Levi
Levi - avatar
0
Levi No in python function can be return as a variable so there is return Inner Assigned returned function to a variable r_print but actually it is a function so there is r_print() also we can pass function as an argument so there is decor(display)
30th Aug 2022, 9:30 AM
A͢J
A͢J - avatar