2011-10-22 129 views
45

我有一个脚本读取输入并将其列出,但我希望它将大写字母转换为小写,我该怎么做?如何将大写字母转换为小写

这是我得到

for words in text.readlines(): 
    sentence = [w.strip(',.') for w in line.split() if w.strip(',.')] 
    list.append(sentence) 
+5

如果你发现'str'的​​'strip'和'split'方法,搜索'upper'和'lower'有多难? – JBernardo

+5

请在这里输入这些东西到谷歌之前,python文档命中1并有正确的答案。 为了记录答案是'thestring.lower()' – Serdalis

回答

95

您可以在文档的部分5.6.1. String Methods与Python字符串更多的方法和功能。

w.strip(',.').lower() 
21

str.lower()将所有插入的字符转换为小写。

3

要在Python中将字符串转换为小写,请使用类似下面的内容。

list.append(sentence.lower()) 

我在搜索“python upper to lower case”后发现了第一个结果。

相关问题