Referential Magic in Python
karamatli.com
karamatli.com
def a(x):
x = 42
and expect the value of `y` in your local scope to be changed after `a(y)`.I'd rather agree with the way Java defines it - call by value.
Wikipedia: However, the term "call by sharing" is not in common use; the terminology is inconsistent across different sources. For example, in the Java community, they say that Java is pass-by-value, whereas in the Ruby community, they say that Ruby is pass-by-reference, even though the two languages exhibit the same semantics.
One of the trouble in python is if you really want to pass a reference to a true value such as an int. Usually I just wrap the int value in a list object because the syntax is fairly concise. Of course if you can you should avoid it, and in python 3 the most common occurrence is fixed with the nonlocal statement (which allows you to access the value of an outer scope, required with closures and non-reference values).
The way I understand what you're saying - no - you don't pass "an object". In case of objects in Python, Java and others the value you pass then is a reference to that object. That reference cannot change in the calling scope.
No, it's always a reference to an object. It's just that some objects are immutable and so the distinction is not so clear. Otherwise, all-around agreement. +1