string does not support item assignment

Comments   0   Date Arrow  June 20, 2008 at 2:43pm   User  by pichai

a = ‘abc’
a[1] = ‘x’
print a
Have Error
Traceback (most recent call last):
File “<pyshell#1>”, line 1, in <module>
a[1] = ‘x’
TypeError: ’str’ object does not support item assignment
Change to
a = ‘abc’
a = a[:1] + ‘x’ + a[2:]
print a

Tagged   Programming · Python  delicious  Comments  Add Your Comment