On Sat, Nov 16, 2019 at 5:41 PM Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote: > > On 16/11/19 8:22 am, Chris Angelico wrote: > > That's the typical sort of description you get from someone who mostly > > understands Python's semantics, but is hung up on the idea that > > everything is either call-by-value or call-by-reference, and is trying > > to figure out which box Python fits into. > > Or they may have read the definition of "call by value" in the > Algol60 report, which says that "The actual parameter expression > is evaluated and the result is assigned to the formal parameter." > Which is exactly what Python does... >
This is 100% true, but actually just punts on the question of "call-by-X". All the subtleties are bound up in this little bit: > the result is **assigned** to the formal parameter Which is actually a really REALLY good way to start peeling things back. In Python - and in many many other languages - the semantics of function calls can be summarized as assignment. You evaluate an expression in the caller's context, and assign the result to a local name in the callee's context. So far, C and Python both have the exact same semantics. So the real question is: What is assignment? And that's where everything about name binding comes in. In C, that assignment operates on a bit-copying level, cloning some value (which might be a pointer). In Python, that same assignment operates as a name binding, giving the target a reference to some particular object. ChrisA -- https://mail.python.org/mailman/listinfo/python-list