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

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

    As Mark pointed out, you should use .title():

    "MyAwesomeString".title()
    

    However, if would like to make the first letter uppercase inside a Django template, you could use this:

    {{ "MyAwesomeString"|title }}
    

    Or using a variable:

    {{ myvar|title }}
    

提交回复
热议问题