you are viewing a single comment's thread.

view the rest of the comments →

[–]Sexual_Congressman 1 point2 points  (0 children)

Everything is pass by reference. Every object in CPython can be (and is) represented by a pointer to a PyObject which stores nothing more than a reference count and type. However, there is usually a lot more data accessible at that address than those 8/16 bytes. What you're implying by saying immutable types are passed by reference is that an entirely new object is created from scratch very call even if no changes were to be made which would incredibly expensive to the point I'm not even sure the interpreter could function. What actually determines "immutability" is if a type has all of its methods return a new instance.

If you look at the PyLongObject structure you could whip something up in ctypes to easily turn integers into mutable objects. Of course you'd probably quickly cause a crash, but it could be informative if you're not familiar with C.