Questions: Function Parameters and Argument Passing
5 questions to test your understanding
Score: 0 / 5
Question 1 Multiple Choice
In Python, consider: `def double(x): x = x * 2`. After running `n = 5; double(n)`, what is the value of n?
A10 — the function modified x, and x was bound to n
B5 — x is a local variable; reassigning x inside the function does not affect n
CNone — functions without return statements set caller variables to None
DAn error occurs because x is modified inside the function
When `n` is passed to `double`, the parameter `x` receives a copy of the value 5. Reassigning `x = x * 2` only changes the local variable `x` inside the function — it does not reach back and change `n` in the caller. For simple immutable types like integers, the parameter is effectively a local copy. This is a key distinction: modifying the parameter's value (reassignment) is different from mutating the object the parameter points to.
Question 2 Multiple Choice
A function is defined as `def append_zero(lst): lst.append(0)`. After running `my_list = [1, 2]; append_zero(my_list)`, what is `my_list`?
A[1, 2] — the function worked on a copy of the list
B[1, 2, 0] — the parameter referred to the same list object in memory
C[0] — the function replaced the list's contents
DAn error — lists cannot be passed as arguments
Lists are mutable objects. When `my_list` is passed to `append_zero`, the parameter `lst` points to the *same list object* in memory — not a copy. Calling `lst.append(0)` mutates that shared object, so the change is visible in the caller through `my_list`. This contrasts with the integer case: here the function didn't *reassign* `lst` (which would have had no effect on `my_list`); it *mutated* the object `lst` refers to.
Question 3 True / False
Modifying a parameter inside a function usually changes the original variable that was passed as the argument.
TTrue
FFalse
Answer: False
Whether the original is affected depends on whether you mutate the object (changes are visible) or reassign the parameter (no effect on caller). For immutable types like integers and strings, 'modification' necessarily means reassignment, so the caller is never affected. For mutable types like lists, calling a mutating method (`.append()`, `.sort()`) affects the shared object, but reassigning the parameter (`lst = []`) does not reach the caller.
Question 4 True / False
The terms 'parameter' and 'argument' refer to different things: parameters are the named placeholders declared in a function's definition, while arguments are the actual values supplied when the function is called.
TTrue
FFalse
Answer: True
This distinction is precise and useful. In `def greet(name):`, `name` is a parameter — a formal variable in the function signature. In `greet('Alice')`, `'Alice'` is the argument — the actual value bound to that parameter at call time. Conflating the two makes it harder to reason about function definitions versus function calls, and obscures the mechanics of how values flow into and through functions.
Question 5 Short Answer
Explain why calling `lst.append(42)` inside a function changes the caller's list, but assigning `lst = []` inside the same function does not.
Think about your answer, then reveal below.
Model answer: When a list is passed as an argument, the parameter `lst` and the caller's variable both point to the same list object in memory. Calling `lst.append(42)` mutates that shared object, so the change is visible through both references. Assigning `lst = []` only rebinds the local variable `lst` to a new empty list — it breaks `lst`'s connection to the original object without affecting the caller's variable, which still points to the original list.
This is Python's 'pass-by-object-reference' model. The parameter and the argument start as two names for the same object. Mutation changes the object itself (seen by everyone who holds a reference). Reassignment changes which object the local name refers to (invisible to the caller). Understanding this distinction prevents an entire class of bugs where functions unexpectedly do or do not modify the data passed to them.