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 another string, possibly of a different length?
str[1:6]
Strings are immutable in Python. The best you can do is construct a new string:
t = s[:1] + "whatever" + s[6:]
1.4m articles
1.4m replys
5 comments
57.0k users