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

前端 未结 19 2344
深忆病人
深忆病人 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:45

    If only you want the first letter:

    >>> 'hello world'.capitalize()
    'Hello world'
    

    But to capitalize each word:

    >>> 'hello world'.title()
    'Hello World'
    

提交回复
热议问题