You can see here: http://thomaschen2011.iteye.com/blog/1441254
- Immutable object: Int,string,float,tuple
- Variable object: list,dictionary
Mutable objects and immutable objects in Python, like literal meaning, mutable objects can be changed once they are created, but the address does not change, that is, the variable points to the original object. Immutable objects, in contrast, cannot be changed after they are created, and if changed, the variable points to a new object.
Give me a chestnut:
>>> s ='ABC' #Immutable Objects>>>ID (s)3072200191 >>> S + ='D'3072200325 >>> L = ['a','b','C']#mutable Objects>>>ID (L)3072200074 >>> L + ='D'>>>ID (L)3072200074
It is found that adding elements to an immutable object causes the variable to point to the object address to change, and the variable object address does not change.
Python built-in object, in Variable object list, Dict. Immutable Object str, int., tuple, float
D
Python mutable objects and immutable objects