类似于word中的替换操作,我们可以用replace来把一个字符串中的某些字符用新的字符替换,类似于英文replace a with b的语法,具体的代码如下:
s = "I love python!"
sr = s.replace('o','O')
print(sr)
运行结果如下:
I lOve pythOn!
[Finished in 0.6s]
我们看到,我们replace 了o with O。
类似于word中的替换操作,我们可以用replace来把一个字符串中的某些字符用新的字符替换,类似于英文replace a with b的语法,具体的代码如下:
s = "I love python!"
sr = s.replace('o','O')
print(sr)
运行结果如下:
I lOve pythOn!
[Finished in 0.6s]
我们看到,我们replace 了o with O。