Python使用新值替换旧值

'''
https://www.cnblogs.com/xiazhenyu/
*** 学而思之、思而记之、记而习之 ***
'''
stra = "8888"
strb = "幸运数字 8888"
strc = "666"
if stra in strb:
# 满足条件 ,使用新值替换旧值
strd = strb.replace(stra, strc) # 左边是旧值,右边是新值
print(strd) # 输出结果:幸运数字 666
原文地址:https://www.cnblogs.com/xiazhenyu/p/13727504.html