如何在python中的点(。)之后更改大写单词

时间:2018-03-20 11:09:58

标签: python

我想找到一种方法,如何更改python中句点(。)之后的第一个字母?

示例:

hello world. this is test. please help 

我想要的结果是:

Hello world. This is test. Please help.

我试过这样,但它不起作用:

text = 'hello world. this is test. please help'
print text.capitalize()

1 个答案:

答案 0 :(得分:3)

试试这个:

sentence = "hello world. this is test. please help."
print(". ".join(i.capitalize() for i in sentence.split(". ")))