I've seen in several places, including the Python documentation that Python uses pass by "assignment" semantics. Coming from a Java background, where the common mistake of saying "Java passes primitives by value, and objects by reference" is as a result of having objects references passed by value, I can't help but wonder if Python is really doing the same thing.
To me, the concepts of passing object references by value and pass by assignment seem identical. Is Python's use of the term "pass-by-assignment" an attempt to mitigate the problem of having erroneous statements such as the one I described above? If so, is it fair to say that parameter passing works in a similar way in the two languages?
Edit: I don't think that this question is a duplicate. Here I'm asking about the terminology used by Python, with direct reference to how Java does things. The other question is about whether the language is pass-by-value or pass-by-reference. I know that pass by assignment is the nomenclature used here, but my contention, which seems to be supported by the accepted answer, is that this is really no different to how Java does things; it's just a different name.
Yes Python seems to be equivalent to Java in this respect. From http://learnpython.pbworks.com/w/page/15956522/Assignment :
But you must be careful about what is meant by "changes to parameters". Assigning a new value to a parameter name (inside the function, a parameter is just a local variable) does not change the original object--it only rebinds the local variable to a new object.
So, Python passes "object references" "by value".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With