The 6 AI Engineering Patterns, come build with Greg live:Β Starts Jan 6th, 2025
Leverage
Glossary

Immutable

Immutable and mutable data types in Python

In Python, immutable means you are not able to edit something. Mutable means you are. This is due to the way the data types are created in Python. Don’t fear, this isn’t a blocker, there is always a solution if you run into a problem.

The common types of immutable data are int, float, bool, str, tuple.

my_string = "Data"
my_string[2] = "T

>>> TypeError: 'str' object does not support item assignment

Python Immutable

If you run into an immutable object, and you need to edit it, then you’ll need to change the data type. For example: change your tuple to a list or dict.

Let’s look at a quick code sample.

Link to code

On this page