+ 3
List is mutable or not ?
if yes then why
4 Respostas
+ 7
Yes, List is mutable because @Tiago and @anon has answered.
i don't have anything to add.😮
+ 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!
+ 2
Mutable because It's not immutable. It can be changed, appended and such.
+ 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...