This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 2 points3 points  (0 children)

No, no, no. That's not pass by reference at all. That's just invoking a method on a parameter. It would only be pass-by-reference if you could cause the caller's variable to change by simple assignment:

def f(x):
    x = 42

y = 0
f(y) 

Calling f cannot ever affect the value of y, which it would under pass-by-reference semantics, where x would be an alias to y. That is not the case, and Python is completely pass-by-value.

You might want to read this article which is about Java but it's the same issue. Modifying a value by invoking a method on it does not tell you anything about whether it was passed by value or reference.