On Nov 3, 2008, at 2:36 PM, Aaron Brady wrote:

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.

Python can do the swap operation on mutable types, for example.

That's in the "no fair" category. C can do a swap operation on mutable types, too, though it also has only pass-by-value. Same for Java, or for REALbasic or VB.NET using "ByVal" mode. The fact that you can mutate mutable types has absolutely nothing to do with whether the parameter was passed by reference or value. If was by reference, you can change it (the parameter itself, not something the parameter may refer to). If it's by value, you can't.

In Python, you can't.  That's because parameters are passed by value.

By-Value and By-Reference are not the only passing methods.  True or
False?

True, but the others are rarely used and don't apply to any of the languages we've been discussing.

Best,
- Joe

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to