Questions: Parameter Passing: Value vs. Reference

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

In Python, `def f(lst): lst.append(99)` is called with `mylist = [1, 2, 3]; f(mylist)`. What does `mylist` contain after the call?

A[1, 2, 3] — Python uses pass-by-value, so the function received a copy of the list
B[1, 2, 3, 99] — the function mutated the shared object through the copied reference
CIt depends on whether mylist was declared global inside the function
D[99] — appending inside a function replaces the original list
Question 2 Multiple Choice

In Python, `def g(lst): lst = [10, 20, 30]` is called with `mylist = [1, 2, 3]; g(mylist)`. What does `mylist` contain after the call?

A[10, 20, 30] — reassignment inside the function replaces the caller's list
B[1, 2, 3] — reassignment rebinds only the local parameter; the caller's reference is unaffected
C[] — reassignment always clears the original list before binding to the new one
D[1, 2, 3, 10, 20, 30] — reassignment concatenates to the original list
Question 3 True / False

In pass-by-value, modifying the parameter variable inside the function changes the original variable in the caller.

TTrue
FFalse
Question 4 True / False

In Python and Java, when an object is passed to a function, the reference to that object is passed by value — meaning the function can mutate the object's contents but cannot redirect the caller's variable to a different object.

TTrue
FFalse
Question 5 Short Answer

Explain the difference between mutating an object and reassigning a parameter in Python. Why does one affect the caller but not the other?

Think about your answer, then reveal below.