Computer Science I / Functions and Parameter Passing
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
  1. Python passes references either way.
  2. 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.

Read the lesson: Functions and Parameter Passing →

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