You can download this code by clicking the button below.
This code is now available for download.
Capitalize the first letter of each word in the input sentence while making the rest of the letters lowercase.
Technology Stack : str.split(), list comprehension, str.capitalize(), str.join()
Code Type : String processing
Code Difficulty : Intermediate
def capitalize_words(sentence):
"""
将句子中的每个单词首字母大写。
"""
words = sentence.split()
capitalized_words = [word.capitalize() for word in words]
return ' '.join(capitalized_words)