Capitalizes the first letter of every word in a string.
- Use
str.title()
to capitalize the first letter of every word in the string.
代码实现
def capitalize_every_word(s):
return s.title()
使用样例
capitalize_every_word('hello world!') # 'Hello World!'
翻译自:https://www.30secondsofcode.org/python/s/capitalize-every-word