Python Strings Immutability
Why are Python Strings Immutable?
Strings in Python are “immutable” which means they can not be changed after they are created. Some other immutable data types are integers, float, boolean, etc.
The immutability of Python string is very useful as it helps in hashing, performance optimization, safety, ease of use, etc.
The article will explore the differences between mutable and immutable objects, highlighting the advantages of using immutable objects. It will also compare immutability with mutability, discussing various methods to handle immutability and achieve desired outcomes.
Input: name_1 = "Aarun"
name_1[0] = 'T'
Output: TypeError: 'str' object does not support item assignment
Explanation: We cannot update the string after declaring it means once an immutable the objects instantiated, its value cannot be changed