Is 'everything' a refrence or isn't it?
mwm at mired.org
Wed Jan 4 18:10:29 EST 2006
Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> On Wed, 04 Jan 2006 10:54:17 -0800, KraftDiner wrote:
>> I was under the assumption that everything in python was a refrence...
>> so if I code this:
>> lst = [1,2,3]
>> for i in lst:
>> if i==2:
>> i = 4
>> print lst
>> I though the contents of lst would be modified.. (After reading that
>> 'everything' is a refrence.)
> See, this confusion is precisely why I get the urge to slap people who
> describe Python as "call by reference". It isn't.
Except this doesn't have *anything at all* to do with python being (or
not being) call by reference. This is a confusion about name binding
vs. assignment to a variable. The proper people to slap around for
this case are the ones who talk about assignment to a variable.
> It is "call by object" -- you pass around *objects*. Internally, this is
> quite fast, because the entire object doesn't need to be moved, only
> pointers to objects, but you don't get the behaviour of either call by
> reference or call by value.
No, you get *exactly* that behavior from call by reference when you
start passing objects around by reference. If I declare a C object as
"struct foo bar" and do the C "call-by-reference" hack of passing
&bar, I get the exact same behavior I get when I pass an object
referenced by bar to a Python subroutine.
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list