小编Osc*_*son的帖子

在索引中使用python中的replace()方法

我想做这样的事情.

example_string = "test"
print(example_string.replace(example_string[0], "b"))
Run Code Online (Sandbox Code Playgroud)

期待输出

best
Run Code Online (Sandbox Code Playgroud)

但是因为字母"t"被传递到方法中,所以最后的t也被替换为"b".导致输出

besb
Run Code Online (Sandbox Code Playgroud)

如何以一种导致输出"最佳"而不是"besb"的方式来实现?

python replace

3
推荐指数
3
解决办法
1万
查看次数

标签 统计

python ×1

replace ×1