Python is an Object-oriented programing language so everything in Python is an object. There are two types of objects in python i.e. Mutable and Immutable objects.
The difference between both types of objects is Simple, a mutable object can be changed after it is created, and an immutable object can’t.
Types of objects in Python
Understand with example.
These are quicker to access and are expensive to change because it involves the creation of a copy.
Check tuples are immutable or not?
tuple1 = (1, 2, 3) tuple1 = 4 print(tuple1)
Output: TypeError: ‘tuple’ object does not support item assignment
Check strings are immutable
msg = "Hello" msg = 'Bye' print(msg)
Mutable Objects :
Let’s see lists are mutable or not?
al = ["A", "B", "C"] print(al) al = "D" al[-1] = "E" print(al)
[‘A’, ‘B’, ‘C’]
[‘D’, ‘B’, ‘E’]
Do comment if you have any doubts and suggestions on this Python object tutorial.
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.