def capitalize_words(sentence):
words = sentence.split()
capitalized_words = [word.capitalize() for word in words]
return " ".join(capitalized_words)
# 示例输入
sentence = "hello world, how are you?"
# 调用函数并打印结果
print("首字母大写后的句子为:", capitalize_words(sentence))
标签:并打印,word,sentence,python,capitalized,words,capitalize From: https://blog.51cto.com/u_16058927/7092924