python怎么替换字符串中的字母
在Python中,你可以使用replace()
方法来替换字符串中的字母。replace()
方法接受两个参数,第一个参数是要被替换的字母,第二个参数是替换后的字母。下面是一个例子:
string = "Hello World"
new_string = string.replace("o", "e")
print(new_string)
输出结果为:
Helle Werld
在上面的例子中,我们用replace()
方法将字符串中的所有字母"o"替换为"e"。
阅读剩余
THE END