小册名称:Python合辑4-130个字符串操作示例
在Python中替换字符串的多个子字符串
s = "The quick brown fox jumps over the lazy dog"for r in (("brown", "red"), ("lazy", "quick")): s = s.replace(*r)print(s)
s = "The quick brown fox jumps over the lazy dog"
for r in (("brown", "red"), ("lazy", "quick")):
s = s.replace(*r)
print(s)
Output:
The quick red fox jumps over the quick dog