AI engineering glossary · Python core

What is immutable?

Immutable: Describes an object whose contents cannot change after creation. Integers, floats, strings, tuples, frozensets and bytes are immutable in Python. Any apparent change produces a new object, and immutability is what lets such objects be used as dictionary keys.

Level: beginnerTopic: Python core

Immutable: an example

s = 'cat'; s[0] = 'b' raises TypeError. s.replace('c', 'b') returns a new string 'bat' and leaves s unchanged.

Related terms

More Python core terms

Where you learn it

Immutable is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.