+ 3

List is mutable or not ?

if yes then why

30th Mar 2017, 11:16 PM
SANKET VISHWAKARMA
SANKET VISHWAKARMA - avatar
4 ответов
+ 7
Yes, List is mutable because @Tiago and @anon has answered. i don't have anything to add.😮
31st Mar 2017, 1:22 AM
Agus Mei
Agus Mei - avatar
+ 4
List is mutable because they can change "in place". Best to understand with an example: # Strings are immutable x = 'foo' y = x print x # prints foo y += 'bar' print x # prints foo # Lists are mutable x = [1, 2, 3] y = x print x # prints [1, 2, 3] y += [3, 2, 1] print x # prints [1, 2, 3, 3, 2, 1] Notice that in the last example we change y but x also changes!
30th Mar 2017, 11:37 PM
Tiago Silva
Tiago Silva - avatar
+ 2
Mutable because It's not immutable. It can be changed, appended and such.
30th Mar 2017, 11:18 PM
anon
anon - avatar
+ 2
Yes, lists are mutable because they can be changed. for example: x = [1,2,3,4,5] x.append (6) x.insert (0,0) print(x) Now this would result in x = [0,1,2,3,4,5,6] hence they can be changed. hope that helps...
1st Apr 2017, 5:52 PM
Rajveer Patel
Rajveer Patel - avatar