
Referential Magic in Python - mahipal
http://karamatli.com/pages/lang/Referencial_Magic_in_Python/
======
viraptor
I think the article makes the matter more confusing than it should be.
Actually many people make it more confusing. Just like with Java, Python
passes only values. The value can be a reference to an object sometimes -
that's pretty much it. Just like with Java, the call-by-whatever is sometimes
misunderstood. It never behaves like call-by-reference. You can never do:

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

~~~
bfw
Unless of course the value you pass is an object. In which case it will change
in the scope you called the function from.

~~~
driax
The point is that you can't pass an object. The object lives on the heap and
you always pass references around. Thats why when we pass in a list we can
change the contents. The passed-in value is a copy of the reference to our
list object.

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

