Python is a powerful programming language that offers two types of objects: mutable and immutable. In this article, we will discuss the key differences between these two object types and how they can be used in Python programs.
About Difference Between Mutable And Immutable In Python
Mutable | Immutable |
---|---|
Objects can be modified after creation. | Objects cannot be changed after they are created. |
Can modify, add or remove elements. | Cannot alter the object in any way. |
Examples: Lists, dictionaries, sets. | Examples: Strings, tuples, numbers. |
Data is stored in memory. | Data is stored as values. |
Identity remains same. | Identity changes when modified. |
Changes are visible outside scope. | Changes remain within scope. |
— by
Leave a Reply