Python Fundamental Data Types vs Immutability
֍ All Fundamental Data types are immutable. i.e once we create an object,we cannot
perform any changes in that object. If we are trying to change then with those changes
a new object will be created. This non-changeable behavior is called immutability.
֍ In Python if a new object is required, then PVM won’t create object immediately. First
it will check is any object available with the required content or not. If available then
existing object will be reused. If it is not available then only a new object will be
created. The advantage of this approach is memory utilization and performance will be
improved.
֍ But the problem in this approach is, several references pointing to the same object, by
using one reference if we are allowed to change the content in the existing object then
the remaining references will be effected. To prevent this immutability concept is
required. According to this once creates an object we are not allowed to change
content. If we are trying to change with those changes a new object will be created.
>>> a=10
>>> b=10
>>> a is b
True
>>> id(a)
1572353952
>>> id(b)
1572353952
>>>