title: Confusing recursion in Python
body: <p>I'm going back to the basics about python and got really confused about recursions, here's a really simple sample code I used,</p>
  <pre class="lang-py prettyprint-override"><code>def factorial(n):
      if n == 1:
          print('Return Value 1')
          return 1
      else:
          print('Recursively calling factorial: ',n-1)
          result = n*factorial(n-1)
          print('Returning: ', result)
          return result
  </code></pre>
  <p>Calling  factorial(5) it outputs</p>
  <pre><code>    Recursively calling factorial:  4
      Recursively calling factorial:  3
      Recursively calling factorial:  2
      Recursively calling factorial:  1
      Return Value 1
      Returning:  2
      Returning:  6
      Returning:  24
      Returning:  120
  </code></pre>
  <p>I was confused because why does it first prints all the 'Recursively calling factorial:' then all the results in ascending order?</p>
  <p>I was expecting python to read line by line and an output as something like this but I was wrong.</p>
  <pre><code>    Recursively calling factorial:  4
      Returning:  120
      Recursively calling factorial:  3
      Returning:  24
  </code></pre>