如何删除该字符串中的所有字符实例? 以下是我的代码:
def findreplace(char, string):
place = string.index(char)
string[place] = ''
return string
然而,如果我运行它,会发生这样的情况:
>>> findreplace('i', 'it is icy')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in findreplace
TypeError: 'str' object does not support item assignment
为什么会这样?