Python Immutable data types are objects that cannot be modified and altered. This means after creating an object you can’t add new elements, remove an element, or replace an element.
Here is a list of immutable data types in Python are:
Example Immutable data types in Python
Simple example code immutable object can’t be changed after it is created.
Tuples are immutable
tup1 = (1, 2, 3) tup1 = 4 print(tup1)
Strings are immutable
greeting = "Welcome to EyeHunts" greeting = 'Hello' print(greeting)
Output: TypeError: ‘str’ object does not support item assignment
Do comment if you have any doubts or suggestions on this Python Immutable object topic.
Note: IDE: PyCharm 2021.3.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.