Totally Confused: Passing variables to functions
cdreward at riaa.com
Thu Jun 5 13:26:31 CEST 2003
>> This doesn't seem very intuitive,
', which leads me to believe I'm missing "the big picture".', as I said. I'm
sure it is all very simple, once understood.
I'm new here...
> >>> v = [1,2]
> >>> arg = v
> >>> arg.append(3)
> >>> v
> [1, 2, 3]
I'm not "getting" variables in Python, then.
What exactly happens when I say "arg = v"?
Not "arg is assigned the value [1,2] that v happens to hold"...
Not "arg now points to v" (can't be, since you can delete v and arg still
It seems to say, "arg now points to what v also points to".. is this correct?
a = 1
b = a
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?
If so, I *think* I'm starting to "get it"... ;-)
>Same as your original function, right?
Seems that way.
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
More information about the Python-list