replace函数

# repalce(old,new,[max])
#
# 说明:
# replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串)
# 如果指定第三个参数max,则替换不超过 max 次。
#
# 语法:
# str.replace(old, new[, max])
#
# 参数:
# old -- 将被替换的子字符串。
# new -- 新字符串,用于替换old子字符串。
# max -- 可选字符串, 替换不超过 max
#
# 返回值:
# 返回新的字符串
#
# 实例

s1 = "ABCD"
s2 = "ab"
res = s1.replace(s1,s2)
print(res) #ab
原文地址:https://www.cnblogs.com/shadowfolk/p/14768664.html