how are strings immutable in python?
Mark Tolonen
M8R-yfto6h at mailinator.com
Sun Jul 6 17:55:35 EDT 2008
"ssecorp" <circularfunc at gmail.com> wrote in message
news:a08a6406-6d54-402c-9271-9d1940f3dff6 at z72g2000hsb.googlegroups.com...
> 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']
--Mark
More information about the Python-list
mailing list