Finding the instance reference of an object
Aaron Brady
castironpi at gmail.com
Mon Nov 3 16:36:01 EST 2008
On Nov 3, 2:44 pm, Joe Strout <j... at strout.net> wrote:
> On Nov 3, 2008, at 12:00 PM, Aaron Brady wrote:
>
> > I think we can conclude that Python passes by reference, since a
> > function can modify objects that were passed in to it.
>
> Then please write the Python equivalent of the "Swap" methods shown at
> <http://www.strout.net/info/coding/valref/> (or at <http://javadude.com/articles/passbyvalue.htm
> >, for that matter).
>
> And no fair wrapping the two parameters up in an object or using tuple
> packing/unpacking -- the point is to demonstrate that you can change
> the two parameters themselves, not some object that contains them or
> return them a different order.
>
> And by the way, if mutating an object a parameter refers to qualifies
> as pass by reference, then Java, VB.NET/REALbasic (in ByVal mode), and
> C/C++ all pass by reference too. That'll be quite a surprise to their
> compiler authors! (I should know, as I'm one of them.)
>
> Best,
> - Joe
Python can do the swap operation on mutable types, for example.
By-Value and By-Reference are not the only passing methods. True or
False?
More information about the Python-list
mailing list