| > Python is call by reference. Change my mind. No need to change your entire mind; just an incorrect definition of call-by-reference. Passing a value which has reference semantics isn't call-by-reference. Your f receives x by value. That value is a reference into a boxed object. The x[0] = 1 does not change x; it changes the boxed object. >>> def f(x):
... x[0] = 1
...
>>> a = [ 0, 2, 3 ]
>>> b = a
>>> f(a)
>>> a is b
True
The f function can do nothing to make "a is b" false.Under pass-by-reference, assigning to x would do that. Under pass-by-reference, we can pass a reference to a, such that a can be replaced, without affecting b. "pass-by {whatever}" refers to the semantics of the parameter and what it receives from the argument expression, and how, not the semantics of the argument object/value. |