+ 2
how to re assign an index's string value in Python
index string
2 ответов
+ 4
Strings are immutable. s = 'Hello', s[1] = 'a' will result in an error (if that's what you're asking).
You can implement a function to alter strings though:
def alter_string(s, index, new):
return s[:index] + new + s[index+1:]
s = 'Hello'
print(alter_string(s, 1, 'a')) # Hallo
0
Do you have an example of what you want? Just add it to the question