且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何替换字符串中某个特定字符的所有出现?

更新时间:2023-11-07 10:04:58

问题是您对replace的结果没有执行任何操作.在Python中,字符串是不可变的,因此任何处理字符串的操作都将返回新字符串,而不是修改原始字符串.

The problem is you're not doing anything with the result of replace. In Python strings are immutable so anything that manipulates a string returns a new string instead of modifying the original string.

line[8] = line[8].replace(letter, "")