On Thu, Mar 11, 2010 at 4:32 PM, Ken G. <beach...@insightbb.com> wrote: > If the following program change list[2] to 2010, replacing 1997 (and it > does), why doesn't the second program work in changing line[ 9:11] to 20 > from 08? > FIRST PROGRAM: > > list = ['physics', 'chemistry', 1997, 2000] > print list[2] > list[2] = 2010 > print list[2] > > OUTPUT: > > 1997 > 2010 > > SECOND PROGRAM: > line = [2010020820841134] > if line[ 9:11] == "08": > line[ 9:11] = 20 > print line[ 9:11] > > OUTPUT: > > "TypeError: 'str' object does not support item assignment." > > > Thanking you all in advance,
First, you seem to have made a mistake in copying your programs: In the second program to get your error message, line = [2010020820841134] should read line = "2010020820841134" As for your question: The error message already says it better than I do: If x is a string, then x[9] = <something> is not allowed, nor is x[9:11] = <something>. -- André Engels, andreeng...@gmail.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor