IT-Hardware & Networking
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Mutable vs Immutable Types in Python
In Python, mutability refers to whether an object can be changed after it is created. Based on this, Python data types are classified as:
Mutable Types (Can Change)
These objects allow modifications without changing their identity (memory location).
Examples of Mutable Types
listdict(dictionary)setbytearrayExample of a Mutable List
Immutable Types (Cannot Change)
Once an object is created, it cannot be modified. Any modification creates a new object in memory.
Examples of Immutable Types
intfloatbooltuplestrfrozensetbytesExample of an Immutable String
Key Differences Between Mutable and Immutable Types
list,dict,setint,float,str,tuple