Python将字符串每一个语句的第一个单词的首字母变成大写。

将以下字符每一个语句的第一个单词的首字母变成大写,“.”代表一句话结束
str1='python has a built-in method named capitalize() to convert the first
character of a string into uppercase and change the rest of the characters
into lowercase, and this method can be used on string data in various ways
without just capitalizing on the first characters. how you can apply
this method in python script in different ways are shown
in this article.'

str1='python has a built-in method named capitalize() to convert the first \
character of a string into uppercase and change the rest of the characters \
into lowercase, and this method can be used on string data in various ways \
without just capitalizing on the first characters. how you can apply \
this method in python script in different ways are shown \
in this article.'

import re

sentences = re.split(r'([.?!][\'"]* *)', str1) #考虑句子以句号、问好、感叹号及引号结尾,同时考虑句尾空格
#print(sentences)
        
print("".join(map(lambda s: s.capitalize(), sentences)))

str1.title()