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" <jmart...@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@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor