Mutable & Immutabe | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Mutable & Immutabe

Difference between mutable and immutable? Why strings is immutable?

13th Mar 2019, 1:45 PM
Tahir Iqbal
Tahir Iqbal - avatar
2 Answers
+ 7
Mutable means that you can take some index of an iterable "av" and do: av[index]=newvalue Strings can't do that so they're immutable. Not the actual definition but a good helper I suppose?
13th Mar 2019, 2:21 PM
๐Ÿ‘‘ Prometheus ๐Ÿ‡ธ๐Ÿ‡ฌ
๐Ÿ‘‘ Prometheus ๐Ÿ‡ธ๐Ÿ‡ฌ - avatar
+ 4
It's just the way Python defined it. Basically it goes like this: Container types like lists, dictionaries or sets are mutable; because the whole point of having them is being able to add stuff, move it around and take it out. Whenever you don't need that (like with numbers or strings) it's safer if they are immutable.
13th Mar 2019, 2:29 PM
HonFu
HonFu - avatar