A programmer writes the following Python code:
def say_hello():
print('Hello!')
say_hello
What happens when this code runs?
AIt prints 'Hello!' once
BIt prints 'Hello!' and then returns to the definition
CNothing is printed — the function is referenced but not called
DPython raises a NameError because say_hello is not yet defined
Writing `say_hello` without parentheses is merely a reference to the function object — it does not execute the function. To call the function and trigger its code, you must write `say_hello()`. This is one of the most common beginner mistakes: assuming that naming a function executes it. Only the parentheses cause execution.
Question 2 Multiple Choice
What is the primary benefit of wrapping repeated code into a named function?
AIt makes the code run faster by pre-compiling the function body at definition time
BIt allows the code to execute once during definition and then be reused cheaply
CIt hides implementation details behind a meaningful name and allows the code to be called multiple times without rewriting it
DIt ensures the function body runs automatically whenever a related variable changes
Functions provide abstraction (the caller doesn't need to know how the code works, only what it does) and reusability (write once, call many times). Option A is false — defining a function does not pre-compile it for speed. Option B is wrong — defining a function does NOT run the code; calling it does. Option D describes a reactive system, not how functions work.
Question 3 True / False
Defining a function in Python causes its code to execute immediately.
TTrue
FFalse
Answer: False
Defining a function (using `def`) only registers the function's name and stores its code as a callable unit. The body executes only when the function is explicitly called by name with parentheses. You can define a function at the top of a file and call it zero, one, or a hundred times later — the definition itself does nothing except make the function available.
Question 4 True / False
A single function definition can be used to produce results at multiple different points in a program.
TTrue
FFalse
Answer: True
This is one of the core values of functions: write the code once, call it wherever needed. Each call executes the function body fresh from the beginning, and control returns to the call site when the function finishes. Functions would be far less useful if each definition could only be invoked once.
Question 5 Short Answer
Explain the difference between defining a function and calling a function, and describe what actually happens during each step.
Think about your answer, then reveal below.
Model answer: Defining a function (using `def` or equivalent) registers the function's name and stores its code — no code in the body executes at this point. Calling the function (writing its name followed by parentheses) triggers execution: the program jumps to the function body, runs through its statements, and then returns to wherever the call was made. Definition is like writing a recipe; calling is like actually cooking it.
This distinction matters for understanding program flow. Many bugs arise from defining a function but forgetting to call it (nothing happens), or from trying to call a function before it has been defined in a language that requires declaration order. The call — not the definition — is the trigger for execution.