Mutability

Some concepts

  • An object’s identity never changes once it has been created.

  • An object’s type defines the possible values and operations. It is unchangeable like the identity.

  • The value of some objects can change, depending on the type.

Some objects contain references to other objects, these objects are called containers (like tuple, list, or dictionary).

Immutable Objects

That’s when we have updated the first string it doesn’t change the value of the second. Immutable data types:

  • int

  • float

  • decimal

  • bool

  • string

  • tuple

  • range

Mutable Objects

  • list

  • dictionary

  • set

  • user-defined classes

Container objects

Some objects contain references to other objects, these objects are called containers (ie, tuple, list, or dictionary). The value of an immutable container that contains a reference to a mutable object can be changed if that mutable object is changed.

However, the container is still considered immutable because when we talk about the mutability of a container only the identities of the contained objects are implied.

Mutable Default Arguments

Last updated

Was this helpful?