Sobes.tech
Junior — Middle

Are all numeric types in Python immutable or are there exceptions?

sobes.tech AI

Answer from AI

In Python, all numeric types (int, float, complex) are immutable. This means that once an object is created, its value cannot be changed — any operations that seem to modify it actually create a new object.

For example:

x = 10
print(id(x))  # object address
x += 5
print(id(x))  # address changed, a new object was created

There are no exceptions among the built-in numeric types — all are immutable. This ensures the safety and predictability of number behavior in Python.