Fundamental Data Types and it's Immutability in Python

 -->All Fundamental Data types are immutable. i.e once we creates 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 wont 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


>>> a=10+5j

>>> b=10+5j

>>> a is b#False

>>> id(a)#15980256

>>> id(b)#15979944


>>> a=True

>>> b=True

>>> a is b#True

>>>id(a)#1572172624

>>> id(b)#1572172624


>>> a='siddu'

>>> b='siddu'

>>> a is b#True

>>> id(a)#16378848

>>> id(b)#16378848



No comments:

Post a Comment

Thank you Very Much.For Given Comment

Downloading Talliki Vandhanam List

--> Citizens can know the status of Talliki Vandhanam Click Here -->Knowing the Status of Talliki Vandhanam   --> In GSWS NBM Login...