Skip to content

Immutable in Python | Object Basics

  • by

Some objects are Immutable in Python. An immutable object’s value can’t change is possible over time. These are of in-built types like int, float, bool, string, Unicode, tuple data type are Immutable in Python.

In simple words, an immutable object can’t be changed after it is created.

Example immutable object in Python

Simple example code check that tuples are immutable. Immutable objects are quicker to access and are expensive to change because it involves the creation of a copy.

tup1 = (1, 2, 3)
tup1[0] = 4

print(tup1)

Output: Tuple object can’t be changed by seeing the below output you get a clear understanding.

Immutable in Python

What built-in objects are immutable in Python

Answer: Objects of the built-in type that are immutable are:

Do comment if you have any doubts or suggestions on this Python basics tutorial.

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.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading