What happen after recursion found base condition?
<p>I am trying to understand recursion , I am following stackoverflow answer <a href="http://stackoverflow.com/questions/717725/understanding-recursion">Understanding recursion</a>   but i am not getting what i am looking. until i have learned this :  <code>" if recursion is in program then below block of code will not execute until recursion found its base condition, once it found its base condition then that recursion will never execute again and now below block of code will execute without recursion "</code> is am getting right ?</p>

<p>Here is a program :</p>

<pre><code>def countdown(n):
    print(n)

    if n == 0:   
        return   

    countdown(n - 1)  # the recursive call

countdown(4)
</code></pre>

<p>I tried to take help of python visualized code , so my confusion is first recursive function will call function again and again until it found base condition ,ok i understand this part ,like in this program it found base condtion if <code>n==0</code> so now n is 0 and return value is 0 , i understand this :</p>

<p><a href="https://i.stack.imgur.com/5UpOT.png" rel="nofollow"><img src="https://i.stack.imgur.com/5UpOT.png" alt="enter image description here"></a></p>

<p>but what happen after ? why  it return result in reverse order after found base condition ? this is my confusion , why its going reverse ? its like first its unpacking values then its packing old values ? from where n=1 came ?? how ??</p>

<p><a href="https://i.stack.imgur.com/O9Exu.png" rel="nofollow"><img src="https://i.stack.imgur.com/O9Exu.png" alt="enter image description here"></a></p>

<p>now n=2 how ? how its going reverse ???? whats happening here ?</p>

<p><a href="https://i.stack.imgur.com/IO7fe.png" rel="nofollow"><img src="https://i.stack.imgur.com/IO7fe.png" alt="enter image description here"></a></p>

<p>now n=3 then n=4 and then at last it goes to first where it started , whats happening here , my big confusion is what happen after base condition found </p>

<p>like in this program :</p>

<pre><code>def listSum(arr, result):
    if not data:
         return result

    print("print final", listSum(arr[1:], result + arr[0]))
    print("print A:", arr[1:])
    print("print B:", result + arr[0])

listSum([1, 3, 4, 5, 6], 0)
</code></pre>

<p>when it found base condition that if list is empty return result so after it found base condition why its printing result it reverse ? </p>

<p><a href="https://i.stack.imgur.com/plb7T.png" rel="nofollow"><img src="https://i.stack.imgur.com/plb7T.png" alt="enter image description here"></a></p>

<p>@deceze already clear the points but i would like to add few points more:</p>

<p>For Understanding this , You have to the understand fundamental of stack , i have <a href="http://stackoverflow.com/a/40049954/5904928">answered here</a> in detail. </p>

<blockquote>
  <p>After recursion find its base condition then what happen or what
  execute its depend on Whether it is Tail Recursion or Head Recursion.</p>
</blockquote>

<p>If its Tail then all code will execute before the recursive call.</p>

<p>If its Head Then rest of code below of Head recursive function will be 
execute.</p>

<blockquote>
  <p>After recursion find its base call it means now stack will start
  returning values which it have stored during recursive calls.</p>
</blockquote>

<p>:</p>

python recursion