confusion about a python recursion function
<p>I got a <code>print_backward</code> function code online, but I am so confusing
about how it works and its output. </p>

<p>The below is my code.</p>

<pre><code>def print_backward(num):
    if num == 10:
        return 
    num += 1
    print(num)
    print_backward(num)
    print("yeah")   
    print(num)
    print()

print_backward(6)
</code></pre>

<p>The below is output.</p>

<pre><code>7
8
9
10
yeah
10

yeah
9

yeah
8

yeah
7
</code></pre>

<p>I can understand how it prints from 7 to 10, since each time it call
recursively, num += 1.</p>

<p>But I am confusing, once num achieves 10, the <code>print_backward</code> should
return, then done. It should not print yeah 10, yeah 9, yeah 8, yeah
7. Why this code has called return, how it still can print? How this code works to print backward, which means why I called <code>print(num)</code>, it
can print from 10 to 7? </p>

<p>On the first runs, the code does not go further than the inner call to <code>print_backward(num)</code>, that is 4 times (like an infinite recursion)</p>

<p>When the argument reaches 10, all the functions return and it goes further, printing the original <code>num</code>+1 with which they were called.</p>

<p>The highest numbers are printed first because the calls where the number is higher return first.</p>

python recursion