To understand recursion you can use package invocation_tree to visualize the recursive calls as they happen. What is important to realize is that each function call has its own local variables (only 'number' in this case), and that in your function you are printing before calling rec_count() and also after that function call returns.
![[Image: rec.gif]](https://i.postimg.cc/SNwV2c1x/rec.gif)
Full disclosure: I am the developer of invocation_tree.
import invocation_tree as ivt # see link above for install instructions def rec_count(number): print(number) # Base case if number == 0: return 0 rec_count(number - 1) print(number) #After recursion meets base case it then moves on to this print statement. #When I step into this print statement, it is printing out the numbers in reverse. #What I don't understand is, how can a print statement loop through this number variable? tree = ivt.blocking() # blocking: press <Enter> to see next step tree(rec_count, 5) # draw tree of rec_count(5)Running the program and pressing <Enter> a number of times now results in:
![[Image: rec.gif]](https://i.postimg.cc/SNwV2c1x/rec.gif)
Full disclosure: I am the developer of invocation_tree.