You can download this code by clicking the button below.
This code is now available for download.
This function takes a string as input and capitalizes the first letter of each word in the string.
Technology Stack : String splitting, list comprehension, string joining
Code Type : String Handling Function
Code Difficulty : Intermediate
def capitalize_words(text):
"""
将输入的字符串中每个单词的首字母大写。
"""
words = text.split()
capitalized_words = [word.capitalize() for word in words]
return ' '.join(capitalized_words)