Totally Confused: Passing variables to functions

Michael Chermside mcherm at mcherm.com
Thu Jun 5 15:00:10 EDT 2003


Chuck writes:
> is really saying, "b points to what a points to, which is a 'variable' with
> the value of 1, which cannot be changed (immutable)".
> 
> Is this correct?

Yes... EXACTLY.

> If so, I *think* I'm starting to "get it"...  ;-)

I'd say you *have* got it.

> So is it safe to say that variables are never "copied" when passed to a
> function in Python? No memory is ever allocated, no "second copy" is made,
> just a.. uhmm.. a "binding" to the original variable you "passed" as the
> argument?

Precisely. It's different from C and Pascal, but it's really QUITE
simple once you figure out out (and you have). The good news is
that Python isn't the only language that works this way. For instance,
Java works exactly the same way whenever operating on objects (but 
not for "primative types" -- that would be too consistant ;-).

-- Michael Chermside






More information about the Python-list mailing list