how are strings immutable in python?

Mark Tolonen M8R-yfto6h at
Sun Jul 6 23:55:35 CEST 2008

"ssecorp" <circularfunc at> wrote in message 
news:a08a6406-6d54-402c-9271-9d1940f3dff6 at
> so if strings were mutable and i did
> a = b = "foo"
> and then did
> a += "bar"
> then a and b would be foobar?

This can be demonstrated with a list of characters, which *is* mutable:

>>> a = b = list('foo')
>>> a += list('bar')
>>> a
['f', 'o', 'o', 'b', 'a', 'r']
>>> b
['f', 'o', 'o', 'b', 'a', 'r']


More information about the Python-list mailing list