text = '''felt happy because I saw the others were happy
and because I knew I should feel happy,
but I wasn’t really happy.'''
print(text.capitalize())
只有第一个单词大写。
从官方文档有关capitalize()
:
返回字符串的副本,其中第一个字符大写,其余字符小写。
您正在寻找的方法是title()
,它将大写每个单词。这是文档中的描述:
返回字符串的标题版本,其中单词以大写字符开头,其余字符为小写。
结果如下:
>>> text = '''felt happy because I saw the others were happy and because I knew I should feel happy, but I wasn’t really happy.'''
>>> print(text.title())
'Felt Happy Because I Saw The Others Were Happy And Because I Knew I Should Feel Happy, But I Wasn’T Really Happy.'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句