Mutable and Immutable Objects
Every thing in python is object. We have to understand all the data represented in python is by object. This object can be immutable or mutable.
Immutable Objects are those which can't be changed .
Ex:- Int, Float, Complex, String, Tuple, Frozen set.
[note: immutable version of set], bytes.
Mutable Objects are :- List, Dict, Set, Byte array etc.
Immutable Ex:-
my_yuple = (10, 20, 30)
print(my_yuple)
output
(10, 20, 30)
continue...
my_yuple = (10, 20, 30)
my_yuple[0] = 40 - - - We are trying to change the first position data.
print(my_yuple)
output:
File "test.py", line 3, in < module >
my_yuple[0] = 40
TypeError: 'tuple' object does not support item assignment
Comments
Post a Comment