Python: String replace index

前端 未结 6 1242
面向向阳花
面向向阳花 2020-12-11 05:04

I mean, i want to replace str[9:11] for another string. If I do str.replace(str[9:11], \"###\") It doesn\'t work, because the sequence [9:11] can b

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 05:11

    str = "cdabcjkewabcef"
    print((str[::-1].replace('cba','###',1))[::-1])
    

提交回复
热议问题