+ 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", }

7th Jun 2018, 7:41 AM
Mohammad Hasibul Haque
Mohammad Hasibul Haque - avatar
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
7th Jun 2018, 7:57 AM
Gopal Gautam
Gopal Gautam - avatar
+ 2
Thank you Jay.
7th Jun 2018, 8:01 AM
Gopal Gautam
Gopal Gautam - avatar
+ 1
thank you all for helping me to understand. thanks a lot.
7th Jun 2018, 7:59 AM
Mohammad Hasibul Haque
Mohammad Hasibul Haque - avatar
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?
7th Jun 2018, 7:53 AM
Mohammad Hasibul Haque
Mohammad Hasibul Haque - avatar