Concept of Mutability (म्यूटेबिलिटी की अवधारणा) :-
Python में Mutability का अर्थ है कि किसी Object को बनाने के बाद उसकी existing value/content को उसी Object में बदला जा सकता है या नहीं।
English
Mutability refers to whether the contents of an Object can be changed after the Object has been created, without creating a new Object.
Python में Data Types को मुख्य रूप से दो categories में समझा जाता है:
ऐसे Data Types जिनके contents को Object बनने के बाद modify किया जा सकता है, उन्हें Mutable Data Types कहते हैं।
English
Data Types whose contents can be modified after the Object is created are called Mutable Data Types.
Python के प्रमुख Mutable Data Types हैं:
ऐसे Data Types जिनके Object बनने के बाद उनके existing contents को उसी Object में modify नहीं किया जा सकता, उन्हें Immutable Data Types कहते हैं।
English
Data Types whose existing contents cannot be modified after the Object is created are called Immutable Data Types.
Python के प्रमुख Immutable Data Types हैं:
Example -
Output-
यहाँ List की existing value 10 को 100 से बदल दिया गया। इसलिए List Mutable Data Type है।
Immutable Example :-
x = (10, 20, 30)
x[1] = 200 #Tuple के existing element को इस तरह change नहीं कर सकते:
इससे TypeError आएगा।
इसलिए:Tuple → Immutable