"always passes by reference"

Roger Upole rupole at compaq.net
Sun Jul 30 13:19:46 EDT 2000


As I understood it, Python is actually two levels of abstraction away from
pass by value.  Normally, 'pass by reference' means that the actual address
of the data in memory is passed.  However, in Python's pass by reference,
rather than the address of the data, it is passing the address of the object
itself,
which contains the address and structure of the data.
It would only seem to work like pass by value when you pass an immutable
object.
The 'pass by Object' term that someone used earlier is IMO the most accurate
description of the mechanism.

           Roger Upole

"(Greg Weeks)" <weeks at golden.dtc.hp.com> wrote in message
news:8m1ksm$kr9$1 at news.dtc.hp.com...
> [I should have mentioned this in my previous response, but I missed it:]
>
> Martijn Faassen (m.faassen at vet.uu.nl) wrote:
> : This seems to be where the confusion comes in. When people claim Python
> : passes by value, because the *references* are being passed by value,
> : that seems to be just stating that the only thing the computer can pass
> : in the end is numbers. If you say that, everything is by value
>
> Not really.  The question is *which* number do you pass to the function:
> the number written in the argument variable or the address of the argument
> variable (which is then implicitly dereferenced).  Perl passes the latter
> (call by reference), Python passes the former (call by value).  So, in
Perl
> you can have:
>
>     $x = 0;
>     f($x);
>     print "$x\n"; # PRINTS 42
>
> Greg





More information about the Python-list mailing list