|—end of file—|
Press the ⍄ key above to move forward through the program, and the ⍃ key to move back.
Consider the code in the table at left.
What will be printed?
To know, we have to know how Python decides
the order in which to run lines of code:
In this lesson we are concentrating only on function calls,
and returning from function calls.
A function call works like this:
Returning from a function works like this:
Note that when you "fall off the end of a function"—which happens, for example, at lines 5,10,16,19— that automatically returns from that function as if a
return statement appeared there.
Clicking on the arrows at the bottom of the code (⍃,⍄) allow you to step through the code one line at a time and see the order in which the program is executed. The red arrow (☛) indicates the next line of code to be executed. Click through the lines of code until you understand how Python chooses which line to execute next.
You may be wondering—how does Python know "where to go back to" when it returns from a function? That is, we know Python should "pick up where it left off"—but how does it remember where it left off?
The answer has to do with something called the run time stack, and that is what we'll explore in lesson 2.