Comment faire pour abaisser une chaîne en Python

Mots clés : pythonstringuppercaselowercasepython

meilleur 5 Réponses Comment faire pour abaisser une chaîne en Python

vote vote

97

s = "Kilometer" print(s.lower()) 
vote vote

83

>>> 'Kilometers'.lower() 'kilometers' 
>>> 'Kilometers'.casefold() 'kilometers' 
>>> "Maße".casefold() 'masse' >>> "Maße".lower() 'maße' >>> "MASSE" == "Maße" False >>> "MASSE".lower() == "Maße".lower() False >>> "MASSE".casefold() == "Maße".casefold() True 
>>> string = 'Километр' >>> string 'Километр' >>> string.lower() 'километр' 
>>> string = 'Километр' >>> string '\xd0\x9a\xd0\xb8\xd0\xbb\xd0\xbe\xd0\xbc\xd0\xb5\xd1\x82\xd1\x80' >>> string.lower() '\xd0\x9a\xd0\xb8\xd0\xbb\xd0\xbe\xd0\xbc\xd0\xb5\xd1\x82\xd1\x80' >>> print string.lower() Километр 
>>> unicode_literal = u'Километр' >>> print(unicode_literal.lower()) километр 
>>> unicode_literal u'\u041a\u0438\u043b\u043e\u043c\u0435\u0442\u0440' >>> unicode_literal.lower() u'\u043a\u0438\u043b\u043e\u043c\u0435\u0442\u0440' 
>>> unicode_from_string = unicode(string, 'utf-8') # "encoding" unicode from string >>> print(unicode_from_string.lower()) километр >>> string_to_unicode = string.decode('utf-8')  >>> print(string_to_unicode.lower()) километр >>> unicode_from_string == string_to_unicode == unicode_literal True 
>>> print string Километр >>> string '\xd0\x9a\xd0\xb8\xd0\xbb\xd0\xbe\xd0\xbc\xd0\xb5\xd1\x82\xd1\x80' >>> string.decode('utf-8') u'\u041a\u0438\u043b\u043e\u043c\u0435\u0442\u0440' >>> string.decode('utf-8').lower() u'\u043a\u0438\u043b\u043e\u043c\u0435\u0442\u0440' >>> string.decode('utf-8').lower().encode('utf-8') '\xd0\xba\xd0\xb8\xd0\xbb\xd0\xbe\xd0\xbc\xd0\xb5\xd1\x82\xd1\x80' >>> print string.decode('utf-8').lower().encode('utf-8') километр 
vote vote

80

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

61

s = input('UPPER CASE') lower = s.lower() 
s = "Kilometer" print(s.lower())     - kilometer print(s)             - Kilometer 
vote vote

52

import string s='ABCD' print(''.join([string.ascii_lowercase[string.ascii_uppercase.index(i)] for i in s])) 
abcd 
s='ABCD' print(s.swapcase()) 
abcd 

Questions similaires