This text is part of a Real Python tutorial by John Sturtz.
Argument Passing Summary
Argument passing in Python can be summarized as follows. Passing an immutable object, like an int
, str
, tuple
, or frozenset
, to a Python function acts like pass-by-value. The function can’t modify the object in the calling environment.
Passing a mutable object such as a list
, dict
, or set
acts somewhat—but not exactly—like pass-by-reference. The function can’t reassign the object wholesale, but it can change items in place within the object, and these changes will be reflected in the calling environment.