immutability is not strictly the same as having an unchangeable value, it is more subtle

Arup Rakshit ar at zeit.io
Tue Apr 16 03:43:18 EDT 2019


Hi, 

I am reading a sweet introduction about Python object from [3.1. Objects, values and types](https://docs.python.org/3/reference/datamodel.html#objects-values-and-types). And here the author is said about the Object values nice way:

> The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. (The value of an immutable container object that contains a reference to a mutable object can change when the latter’s value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value, it is more subtle.) An object’s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.

But what I don’t understand here is that what he said about the immutable container objects. Why after changing the value of internal mutable objects we still say the container object as mutable? Any examples to define what the author meant will be helpful.


Thanks,

Arup Rakshit
ar at zeit.io






More information about the Python-list mailing list