[Tutor] string immutability

Dipo Elegbede delegbede at dudupay.com
Mon Oct 24 21:24:54 CEST 2011


What you did here is just re-assigning s.
Try slicing s and then assign a new value to the slice.
s[2] would return 'r' now try to to set s[2] to another value to understand
immutability.
Hope it helps.

On 24 Oct 2011 19:06, "Johan Martinez" <jmartiee at gmail.com> wrote:

> Hi,
>
> I am struggling to understand Python string immutability. I am able to
> modify Python string object after initializing/assigning it a value. So how
> does immutability work? I am not following it. Sorry for really stupid
> question. Any help?
>
> <code>
>
> >>> s = "First"
> >>> print s.__class__
> <type 'str'>
> >>> print s
> First
> >>> s = "Second"
> >>> print s
> Second
> >>>
>
> </code>
>
> jM.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111024/897f8d07/attachment.html>


More information about the Tutor mailing list