+ 2
Mutable and Unmutable
can someone please explain mutable and unmutable idea and conception to me? thank you. bad_dict = { [1, 2, 3]: "one two three", }
4 odpowiedzi
+ 3
a mutable object can be changed after it is created, and an immutable object can’t. Immutable objects doesn’t allow modification after creation.
**Checking immutability**
>>> a=5
>>> b=a
>>> id(a)==id(b)
True
>>> a=a+1
>>> print(a,b)
6 5
>>>
id(a)==id(b)
False
**Check mutability**
>>> a=[1,2]
>>> b=a
>>> id(a)==id(b)
True
>>> a[0]=3
>>> print(a,b)
[3, 2] [3, 2]
>>> id(a)==id(b)
True
+ 2
Thank you Jay.
+ 1
thank you all for helping me to understand. thanks a lot.
0
so mutable means that I can arrange them in any order. and immutable means that I must state the variable first then it's contents?