Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
int, float, str, tuple, frozenset and bytes are immutable; list, dict, set and most custom objects are mutable. Functions receive references, so changing a mutable argument in place is visible to the caller.
Python passes references to objects, sometimes called pass by object reference. Rebinding a parameter inside a function, such as x = x + 1, only changes the local name and never affects the caller. Mutating a mutable object, such as items.append(4), changes the shared object, so the caller sees the change. Immutable objects cannot be changed in place, so operations on them create new objects. This is why functions that modify their arguments should say so clearly, or copy the input first.