首页 > 代码库 > 给定一个英文句子(一个只有字母的字符串),将句中所有单词变为有且只有首字母大写

给定一个英文句子(一个只有字母的字符串),将句中所有单词变为有且只有首字母大写

def cap_string(sentence):
    sentence=‘ ‘.join([i.title() for i in sentence.split()])
    return sentence

 

s=‘‘‘Python is a programming language that lets you work quickly and integrate systems more effectively‘‘‘     
print cap_string(s)

输出:

Python Is A Programming Language That Lets You Work Quickly And Integrate Systems More Effectively

给定一个英文句子(一个只有字母的字符串),将句中所有单词变为有且只有首字母大写