How do I lowercase a string in Python?

后端 未结 5 1268
星月不相逢
星月不相逢 2020-11-22 12:57

Is there a way to convert a string from uppercase, or even part uppercase to lowercase?

For example, \"Kilometers\" → \"kilometers\".

5条回答
  •  再見小時候
    2020-11-22 13:18

    With Python 2, this doesn't work for non-English words in UTF-8. In this case decode('utf-8') can help:

    >>> s='Километр'
    >>> print s.lower()
    Километр
    >>> print s.decode('utf-8').lower()
    километр
    

提交回复
热议问题