+ 2

The call stack how works?

def func_A(): func_D() func_B() return def func_B(): return def func_C(): func_B() func_E() return def func_D(): func_C() return def func_E(): print("call stack") return who does this work friends help? Is it called like this? func_e func_d func_c func_b func_a if the func_a is called

18th Feb 2021, 6:33 AM
Aid
Aid - avatar
10 Answers
+ 4
A very simple way to find this out is to add print statements in each function describing which function was called, like so https://code.sololearn.com/c9GmiTD9eHK6/?ref=app
18th Feb 2021, 6:58 AM
XXX
XXX - avatar
+ 3
hi Aid the stack is a mathematical contruct which works like... last one inline first one out so when you call func_A() executes the first line immediately puttung func_D() at the top of the stack. func_D() then resolves putting func_C at the top of the stack and so on. does that make sense?
18th Feb 2021, 6:57 AM
Ollie Q
Ollie Q - avatar
+ 2
Ollie Q please tell me where the stack will remain empty?
18th Feb 2021, 7:09 AM
Aid
Aid - avatar
+ 2
Ollie Q after function func_a?
18th Feb 2021, 7:10 AM
Aid
Aid - avatar
+ 2
Ollie Q but the stack will eventually get empty after func_a returns .
18th Feb 2021, 8:11 AM
Abhay
Abhay - avatar
+ 1
You can add to each function print("func_X") and see how it works. Where the X will be the letter from function name
18th Feb 2021, 7:00 AM
Igor Kostrikin
Igor Kostrikin - avatar
+ 1
Aid the stack will not empty because by the time a call to func_B is executed their will be other functions still on the stack to resolve and the interpriter will go through them to
18th Feb 2021, 7:44 AM
Ollie Q
Ollie Q - avatar