Flow, Scope and Program Structure
Flow of a program
A Python script is executed line by line, top to bottom. A function call interrupts the sequential execution of statements, causing the program to execute the statements within the function before continuing. Once the last statement in the function, or a return statement, has executed, flow of control is returned to the point immediately following where the function was called.Function definitions are packaged into an executable unit to be executed later. The code within a function definition executes only when invoked by a caller.
Follow it through. The first call has a = 4, so the if block runs: it prints 4 and returns 6, which is stored in x but not printed yet. The second call has a = 10, so the if is skipped, b is printed giving hi, and the returned value hi! is printed by the caller. Only then does the last line print the 6 that has been waiting in x.
A function that does not return a value actually returns the value None.