In order to ensure that a function is deﬁned before its ﬁrst use, you have to know the order in which statements are executed, which is called the ﬂow of execution.
Execution always begins at the ﬁrst statement of the program. Statements are executed one at a time, in order from top to bottom.
Function deﬁnitions do not alter the ﬂow of execution of the program, but remember that statements inside the function are not executed until the function is called.
A function call is like a detour in the ﬂow of execution. Instead of going to the next state ment, the ﬂow jumps to the body of the function, executes all the statements there, and then comes back to pick up where it left off.
That sounds simple enough, until you remember that one function can call another. While in the middle of one function, the program might have to execute the statements in another function. But while executing that new function, the program might have to execute yet another function!
Fortunately, Python is good at keeping track of where it is, so each time a function completes, the program picks up where it left off in the function that called it. When it gets to the end of the program, it terminates.
What’s the moral of this sordid tale? When you read a program, you don’t always want to read from top to bottom. Sometimes it makes more sense if you follow the ﬂow of execution.