Middle
What data types are immutable in Python?
sobes.tech AI
Answer from AI
In Python, the immutable data types include:
- int (integers)
- float (floating-point numbers)
- bool (boolean values)
- str (strings)
- tuple (tuples)
- frozenset (immutable set)
This means that after creating an object of these types, its contents cannot be changed. For example, a string cannot be modified; only a new string with changed content can be created.
Example:
s = "hello"
s = s + " world" # a new string is created, the original remains unchanged