Immutable Data Classes
Immutable data classes. One of the defining features of the
namedtuple you saw earlier is that it’s immutable, i.e. the value of its fields may never change. For many types of data classes, this is a great idea! To make a data class immutable, set
frozen=True when you create it.
To avoid this, make sure all fields of an immutable data class use immutable types, but remember that types are not enforced at runtime. The
ImmutableDeck should be implemented using a tuple instead of a list.
Become a Member to join the conversation.