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 = "Black" color[-1] = "White" print(color)
Immutable Data Types:
The value assigned to a variable cannot be changed.
greeting = "Welcome to EyeHunts" greeting = 'Hello' print(greeting)
Do comment if you have any doubts and suggestions on this Python data type topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.