[Python] Call by Value, Call by Reference?
How?
To begin with, the correct answer is that python's parameter passing mechanism is call by assignment. It is also referred to as call by object-reference or call by sharing, all of which mean the same thing. In Python, when a function is called, the argument is passed as a reference to the object.
To help understand this, consider that data types like int or str are immutable objects, so even if you try to change their values within a function, the original object will not be affected. On the other hand, for mutable objects like list or set, if you try to modify them inside a function, the original object will also be changed. In other words, it can be understood as a mix of call by value and call by reference.
Object Reference Passing
For immutable objects → call by value
For mutable objects → call by reference