why?
Brian Quinlan
brian at sweetapp.com
Mon Dec 2 17:53:09 EST 2002
> Why does this happen:
>
> >>> 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?
Because, as the exception said, tuples don't support item assignment.
Try changing the second line to:
doing[1] = ['b', 'c']
That will make doing[1] a list, and lists do support item assignment.
Cheers,
Brian
More information about the Python-list
mailing list