In Python, immutable vs mutable data types and objects types can cause some confusionβand weird bugs. With this video course youβll see what the difference between mutable and immutable data types is in Python, and how you can use it to your advantage in your own programs.
Youβll also see how to deal with a language quirk in Python that allows objects referenced by immutable types to me modified. Pythonβs definition of βimmutableβ can be a bit misleading.
Basically, the promise of βimmutabilityβ on tuples is only partly true. The tuple itself cannot be modified, but objects referenced by the tuple can be. This is sometimes called βnon-transitive immutability.β
If the tuple has an immutable field like a string for example, then it cannot be modified. A mutable field like a list however, can be edited, even if itβs embedded in the βimmutableβ tuple.
When the Python documentation refers to an object as being βimmutableβ they mean the behavior above observed. Other immutable types in Python behave the same way, e.g. namedtuples or frozensets.
If youβve ever encountered the following exception and now you want to know why, this is the video course for you:
TypeError: 'tuple' object does not support item assignment




Tonya Sims on July 3, 2019
Wow! This video series cleared up so much confusion for me regarding immutable objects! Thank you Dan!