Thursday 12 September 2019

Python and Java parameter passing

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.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...