How can I splice a string?

前端 未结 5 1611
独厮守ぢ
独厮守ぢ 2020-12-17 14:30

I know I can slice a string in Python by using array notation: str[1:6], but how do I splice it? i.e., replace str[1:6] with anot

5条回答
  •  臣服心动
    2020-12-17 15:08

    You can't do this since strings in Python are immutable.

    Try next:

    new_s = ''.join((s[:1], new, s[6:]))
    

提交回复
热议问题