How to downcase the first character of a string?

后端 未结 8 749
醉酒成梦
醉酒成梦 2020-12-08 12:44

There is a function to capitalize a string, I would like to be able to change the first character of a string to be sure it will be lowercase.

How can I do that in P

8条回答
  •  余生分开走
    2020-12-08 13:38

    One-liner which handles empty strings and None:

    func = lambda s: s[:1].lower() + s[1:] if s else ''
    
    >>> func(None)
    >>> ''
    >>> func('')
    >>> ''
    >>> func('MARTINEAU')
    >>> 'mARTINEAU'
    

提交回复
热议问题