Q11: How does Python pass arguments to functions (Pass-by-Object-Reference)?
Python uses Pass-by-Object-Reference (or Pass-by-Assignment). Variable names are bindings pointing to objects in memory:
- Mutating a mutable object (e.g.
list.append()) alters the object in-place, affecting callers. - Reassigning the parameter variable name (
arg = new_value) breaks the binding, leaving caller variables unaffected.
Key Takeaways
- Mutating mutable arguments modifies original objects.
- Reassigning variable bindings locally does not affect caller bindings.
Knowledge Check
If you pass a list to a function and call list.append(10), will the list outside the function show the change?