Python: String replace index

前端 未结 6 1252
面向向阳花
面向向阳花 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:27

    you can do

    s="cdabcjkewabcef"
    snew="".join((s[:9],"###",s[12:]))
    

    which should be faster than joining like snew=s[:9]+"###"+s[12:] on large strings

提交回复
热议问题