There is disagreement on terminology. In the Java community, they say that everything is passed by value: primitives are passed by value; links are passed by value. (Just find this site for Java and link if you do not believe it.) Note that "objects" are not values ββin the language; only links to objects.
The difference that they use is that in Java, when you pass a link, the original reference variable in the caller area can never be changed (i.e. made to point to another object) as the caller, which should be possible in the link pass. Only the object referenced can be mutated, but it does not matter.
Python values ββwork just like Java references. If we use the same definition, we will say that everything in Python is a reference, and everything is passed by value. Of course, some of the Python community use a different definition.
Disagreement over terminology is the source of much of the confusion.
Since you mention C ++, the Python code you have will be equivalent to something similar in C ++:
void foo(const int *num) { num = new int(*num * 2); } const int *a = new int(4); foo(a); print(a);
Note that the argument is the pointer that most closely resembles references in Java and Python.
source share