September 2026
1051 pages
35h 4m
English
Perhaps you’ve already come across the following seeming contradiction while trying out what we have just described:
>>> a = 1>>> b = 1>>> id(a) 9656320>>> id(b) 9656320>>> a is bTrue
Why do a and b reference the same integer instance, as shown by the identity comparison, even though we explicitly created two instances with the value 1 in the first two lines?
To answer this question, you need to know that Python fundamentally distinguishes between two types of data types—namely, between mutable and immutable data types. As the names suggest, the difference between the two types is whether the value of an instance can change after its creation—that is, whether it’s mutable. Instances of a mutable type ...
Read now
Unlock full access