Practice question · True or false
Whether a function can modify its caller's argument depends on whether the argument is mutable, not on how it was passed.
Hints
- Python passes references either way.
- A list can be changed in place; an integer cannot.
Show the answer
True
Why
True. Python always passes a reference to the object; what differs is whether the object can be mutated. lst.append(x) changes the caller's list, while n += 1 rebinds a local name because integers are immutable. Rebinding the parameter never affects the caller, whatever the type.
Practise Functions and Parameter Passing
The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Functions and Parameter Passing
- For def scale(factor): return factor * 10, later called as scale(60), sort each item by what it is.
- Match each term to its meaning.
- A function with a default argument def f(x, items=[]) behaves strangely: the list keeps its contents between…
- Order what happens when the call y = sq(2 + 3) runs, where def sq(n): return n * n.
- Select every statement about scope that is true.