Is 'everything' a refrence or isn't it?

Steven D'Aprano steve at
Wed Jan 4 20:06:22 EST 2006

Claudio Grondi wrote:

>> See, this confusion is precisely why I get the urge to slap people who
>> describe Python as "call by reference". It isn't.
>> It isn't "call by value" either -- Python never copies objects unless you
>> explicitly tell it to.
>> 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.


> It seems to be hard to explain it all in a straighforward way without 
> using pictures showing what happens when an assignment is processed 
> demonstrating what is what and how it is called. 

That's no different from call by reference or call by 
value. If you think back to when you were first 
learning about pointers, that was confusing too.

> Probably a small nice 
> movie could be here the right medium to be handed over to Python newbies 
> coming from C to give some hints towards proper understanding. Replacing 
> one word with another is not sufficient to avoid confusion as the 
> concept is probably not always easy to grasp (I have still problems to 
> get the idea how it works 'inside' with this local and global 
> dictionaries and so on).

No, just saying "call by object" is not sufficient, but 
it is vital. If you say "call by reference", the term 
comes with a lot of mental baggage -- people think they 
understand what call by reference means, how it 
behaves, and as soon as they hear CBR they think they 
understand how Python behaves. They think "Oh, Python 
is CBR just like language Foo, so it must behave just 
like language Foo, and this idiom works in language 
Foo, so it must work in Python too."

And sometimes it does appear to work, which just makes 
it all the more puzzling when it doesn't.

When they hear CBO the term is new and different and 
doesn't come with any mental frame, so instead of 
thinking they understand Python's behaviour, they think 
"Call by what now? How does that work?" instead of 
making incorrect assumptions.


More information about the Python-list mailing list