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

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

    Why do you complicate your life with joins and for loops when the solution is simple and safe??

    Just do this:

    string = "the brown fox"
    string[0].upper()+string[1:]
    

提交回复
热议问题