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
str[9:11]
str.replace(str[9:11], \"###\")
You can use join() with sub-strings.
join()
s = 'cdabcjkewabcef' sequence = '###' indicies = (9,11) print sequence.join([s[:indicies[0]-1], s[indicies[1]:]]) >>> 'cdabcjke###cef'