how are strings immutable in python?

Mel mwilson at the-wire.com
Sun Jul 6 16:36:13 EDT 2008


ssecorp wrote:
>>>> h = "aja baja"
>>>> h += 'e'
>>>> h
> 'aja bajae'
>>>>
What Peter said, or, to put it another way:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = b = "aja baja"
>>> a += "e"
>>> print a
aja bajae
>>> print b
aja baja

Mutability/immutability makes a difference in programs when different
symbols (or container items) share a value.


        Mel.



More information about the Python-list mailing list