[Tutor] Changing the value in a list
Ken G.
beachkid at insightbb.com
Thu Mar 11 16:32:45 CET 2010
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,
Ken
More information about the Tutor
mailing list