21
How to modify a string in Python
You cannot!
Strings in Python are immutable (something that cannot be changed)
Read here
You can create a new modified string.
original = "My String"
new_string = original.upper()
print(new_string) # "MY STRING"
Since you can't really change the string, the solution is to convert it a mutable type like list
and modify that.
original = "My String"
original_list = list(original)
original_list[0] = 'm'
new_string = "".join(original_list)
print(new_string) # 'my String'
You could also try slicing to speed up the process
21