Hacker News new | past | comments | ask | show | jobs | submit login

> even if the value happens to be a reference to an heap allocated object

IIRC in CPython, the value is always a reference to an object. Other implementations might pass immutable objects directly by value, but the semantics is the same as passing a reference to the object by value.




You are correct. (I'd be surprised if other implementations passed immutable objects by value, partly because representing an "object" coherently requires several words of memory and partly because of the importance of certain object identity semantics.) Python uses pass-by-value (if you prefer, pass-by-assignment) of variables which have reference semantics. Just like non-primitive types in Java, or class types in C#.


> I'd be surprised if other implementations passed immutable objects by value

I'm thinking of MicroPython here - it supports several pointer-tagging schemes, in which "references" might be actual pointers or might instead be immutable values stored directly.

For example, using the NaN-boxing scheme, MicroPython references might actually be inline `float`s, small `int`s, or constants like `None`, `True` or `False`.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: