+ 2

Mutable & Immutabe

Difference between mutable and immutable? Why strings is immutable?

13th Mar 2019, 1:45 PM
Muhammad Tahir Iqbal
Muhammad Tahir Iqbal - avatar
2 Réponses
+ 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