Python Mutable data types are those whose values can be changed in place whereas Immutable data types are those that can never change their value in place.
Here are Mutable data types :
And Immutable data types in Python:
Python Mutable and immutable objects are handled differently. Immutable objects are quicker to access and expensive to change because it involves the creation of a copy. Whereas mutable objects are easy to change.
Examples of mutable and immutable data types in Python
Simple example code.
Mutable Data Types
The value assigned to a variable can be changed. Use it when there is a need to change the size of the data of the object.
color = ["Red", "Green", "Blue"]
print(color)
color[0] = "Black"
color[-1] = "White"
print(color)
Output:
Immutable Data Types:
The value assigned to a variable cannot be changed.
greeting = "Welcome to EyeHunts"
greeting[0] = 'Hello'
print(greeting)
Output:
Do comment if you have any doubts or suggestions on this Python data type topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.