How can I capitalize the first letter of each word in a string?

前端 未结 19 2345
深忆病人
深忆病人 2020-11-22 17:17
s = \'the brown fox\'

...do something here...

s should be:

\'The Brown Fox\'

What\'s the easiest

19条回答
  •  野性不改
    2020-11-22 17:24

    Copy-paste-ready version of @jibberia anwser:

    def capitalize(line):
        return ' '.join(s[:1].upper() + s[1:] for s in line.split(' '))
    

提交回复
热议问题