Strings are immutable, but you can create a list of characters in the string and then process the list. Finally join the list characters to a string again.
Here is an example how to do this ...
# capitalize the sentences in a text string
text = """hello there! my name is Frank.
could I ask you for some spare change?"""
# create a list of characters in the text
char_list = []
for c in text:
char_list.append(c)
# test
print(char_list)
print('-'*50)
# process the list of characters
# turn the leading character of each sentence to upper
lead_char = True
for ix, c in enumerate(char_list):
if lead_char and c.isalpha():
c = c.upper()
# insert changed processed character into list
char_list[ix] = c
# set leading character flag to false
lead_char = False
if c in '?!.':
lead_char = True
# join the list of characters back to a string
new_text = ''.join(char_list)
print(new_text)
''' my result (list has been beautified) -->
['h', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'e', 'r', 'e', '!', ' ',
' ', 'm', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'F',
'r', 'a', 'n', 'k', '.', '\n', 'c', 'o', 'u', 'l', 'd', ' ', 'I',
' ', 'a', 's', 'k', ' ', 'y', 'o', 'u', ' ', 'f', 'o', 'r', ' ',
's', 'o', 'm', 'e', ' ', 's', 'p', 'a', 'r', 'e', ' ', 'c', 'h',
'a', 'n', 'g', 'e', '?']
--------------------------------------------------
Hello there! My name is Frank.
Could I ask you for some spare change?
'''