why?

Erik Max Francis max at alcyone.com
Mon Dec 2 19:03:18 EST 2002


Steve Holden wrote:

> "sami sieranoja" <sami.sieranoja at pp.inet.fi> wrote in message
> news:20021203003514.2abb22e8.sami.sieranoja at pp.inet.fi...
>
> > >>> doing = ['a','b','c']
> > >>> doing[1] = ('b','c')
> > >>> doing[1][0]
> > 'b'
> > >>> doing[1][0] = 'i'
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > TypeError: object doesn't support item assignment
> >
> > Why can't I change that value from 'b' to 'i' ?  Why?
> 
> The short answer is "you just can't". One of the fundamental
> properties of
> any Python type is whether the values are mutable (can be changed) or
> immutable (cannot be changed). Strings are immutable, and that is what
> the
> error message is saying - that the individual characters in the string
> cannot be changed.

Substitute "strings" with "tuples."  The error he got was because he was
trying to modify a tuple, not a string.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Nothing you have said / Is revelation
\__/ The Russian, _Chess_
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list