How to downcase the first character of a string?

后端 未结 8 750
醉酒成梦
醉酒成梦 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:26

    Interestingly, none of these answers does exactly the opposite of capitalize(). For example, capitalize('abC') returns Abc rather than AbC. If you want the opposite of capitalize(), you need something like:

    def uncapitalize(s):
      if len(s) > 0:
        s = s[0].lower() + s[1:].upper()
      return s
    

提交回复
热议问题