Python and Java parameter passing

orrymr

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.

GriffeyDog

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".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Passing function as a parameter in java

From Dev

Java: An Object Constructor Passing Same Object as Parameter

From Dev

basic java parameter passing, computation inside a method

From Dev

Passing parameter to sh file from java class

From Dev

Parameter passing in Java

From Dev

JAVA: Restfull web service not passing parameter correctly

From Dev

Python : Passing function as parameter and multithreading

From Dev

Java - Passing a method through a parameter

From Dev

Passing precision as parameter to python format

From Dev

Passing java object to python

From Dev

Java Passing in Type as Function Parameter

From Dev

Passing a parameter between python classes

From Dev

Passing superclass object as parameter to subclass constructor (java)

From Dev

passing optional dataframe parameter in python

From Dev

PYTHON parameter passing with lists

From Dev

Passing parameter from Java to Python and vise versa

From Dev

passing LotusScript parameter to Java

From Dev

Python :: passing a list as parameter

From Dev

Java Passing Type as parameter into function expecting subtype

From Dev

Passing an object as a parameter in Java

From Dev

passing static method as parameter in Java

From Dev

Passing parameter to anonymous class in Java

From Dev

Passing constructor parameter to method JAVA

From Dev

Java - Passing a method through a parameter

From Dev

passing a column as parameter in python function

From Dev

Java 8 named parameter passing?

From Dev

Passing parameter from Java to Python and vise versa

From Dev

Passing a parameter from Jenkins into Java

From Dev

Using Parameter Passing in Netbeans/Java

Related Related

HotTag

Archive