Immutability
Immutable objects can't be changed in place; without creation of a new variable, you have to create a new object. In of itself, this is inconvenient, but it also implies that none of the internal values can be changed, which—by definition—means that tuples cannot contain lists or any other dynamic objects.
They are made like this on purpose, and this has serious merits. First, the dynamic nature of lists comes with a price: in order to be both dynamic and highly performant, they reserve more memory than they need. Tuples, by comparison, use up to two times less memory! Secondly, and this is the most important part, as tuples are guaranteed to be static, they can be used as an immutable part of other data structures, such as sets ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access