如何将句首和句号后的每个词大写?
到目前为止,我已经能把句子的第一个单词首字母大写了,但我需要的是每个句号后面的第一个字母也要大写。
这就是我现在的代码:
def main():
input1 = input('Enter your input here: ')
capitalize = str.capitalize(input1)
print("The capitalized version:", capitalize)
main()
2 个回答
-2
只需要使用字符串的 .title() 方法就可以了(无论是ASCII还是Unicode都可以)。
对于你的例子:
>>> 'Enter your input here: '.title()
'Enter Your Input Here: '