lists are mutable:
>>> a = [] >>> b = a >>> a += [1] >>> b == [1] True
strings are immutable:
>>> a = "" >>> b = a >>> a += "1" >>> b != "1" True
and strings can be treated as lists in some ways:
>>> "abc"[-1] == "c" True
but
>>> "abc"[-1] = "d" Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment
Is there a helpful way of thinking of how exactly strings are like lists? Clearly there are other differences between them:
>>> hash("a")
7392557238547012712
>>> hash(["a"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
But maybe this is just a side effect of (im-)mutability.