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

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

    A quick function worked for Python 3

    Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> capitalizeFirtChar = lambda s: s[:1].upper() + s[1:]
    >>> print(capitalizeFirtChar('помните своих Предковъ. Сражайся за Правду и Справедливость!'))
    Помните своих Предковъ. Сражайся за Правду и Справедливость!
    >>> print(capitalizeFirtChar('хай живе вільна Україна! Хай живе Любовь поміж нас.'))
    Хай живе вільна Україна! Хай живе Любовь поміж нас.
    >>> print(capitalizeFirtChar('faith and Labour make Dreams come true.'))
    Faith and Labour make Dreams come true.
    

提交回复
热议问题