相关疑难解决方法(0)

如何删除python中字符串中的所有字符实例?

如何删除此字符串中字符的所有实例?这是我的代码:

def findreplace(char, string):
    place = string.index(char)
    string[place] = ''
    return string
Run Code Online (Sandbox Code Playgroud)

但是,如果我运行它,会发生这种情况:

>>> 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
Run Code Online (Sandbox Code Playgroud)

为什么是这样?

python string replace python-2.7

59
推荐指数
2
解决办法
11万
查看次数

标签 统计

python ×1

python-2.7 ×1

replace ×1

string ×1