IsString

Delaney, Timothy (Tim) tdelaney at avaya.com
Thu Dec 15 20:03:12 EST 2005


Chris Mellon wrote:

> <snip a bunch of stuff>
>> Terminology is important, because we understand the world through
>> language. If your language is confused or misleading, your
>> understanding will also be confused or incomplete.
> 
> I think the issue is pretty simple, myself:
> 
> So you could say that Python has both pass-by reference and
> pass-by-value (modulo the fact that pass-by-reference doesn't exist at
> some level, and is a semantic layer on top of pass-by-value. But
> semantics are what we're talking about here).
> 
> However, there is *no way* in Python to get pass-by-value semantics
> with a mutable object, or pass-by-reference semantics with an
> immutable one (you can build your own scaffolding to mimic it, but the
> language won't change it's semantics for you).
> 
> Therefore, it's more correct to say that Python has neither
> pass-by-reference semantics or pass-by-value semantics, but some third
> thing. And thus the name pass-by-object, where the calling semantics
> are that you always get a reference to an object, but what (if any)
> other names are bound to that object, or if they can be bound to that
> object, depends on the object.

You are severely over-complicating things here.

Python does not "pass by" anything. Python has names and objects. When
you assign an object to a name, you are binding that name to that
object. When you assign the object to another name, you are binding the
object to another name. This does not affect the first object binding.
You can still access the contents of the object through either name.

When you pass an object to a function, you bind a new name (the
parameter name) to the object. If you then rebind the name in the
function, the binding to the old object is lost, and the name is bound
to a new object.

Mutability is irrelevant. You can access the object via the bound
parameter name, unless you rebind it.

Tim Delaney



More information about the Python-list mailing list