我有一個腳本讀取輸入並將其列出,但我希望它將大寫字母轉換爲小寫,我該怎麼做?如何將大寫字母轉換爲小寫
這是我得到
for words in text.readlines():
sentence = [w.strip(',.') for w in line.split() if w.strip(',.')]
list.append(sentence)
我有一個腳本讀取輸入並將其列出,但我希望它將大寫字母轉換爲小寫,我該怎麼做?如何將大寫字母轉換爲小寫
這是我得到
for words in text.readlines():
sentence = [w.strip(',.') for w in line.split() if w.strip(',.')]
list.append(sentence)
您可以在文檔的部分5.6.1. String Methods與Python字符串更多的方法和功能。
w.strip(',.').lower()
str.lower()
將所有插入的字符轉換爲小寫。
要在Python中將字符串轉換爲小寫,請使用類似下面的內容。
list.append(sentence.lower())
我在搜索「python upper to lower case」後發現了第一個結果。
如果你發現'str'的'strip'和'split'方法,搜索'upper'和'lower'有多難? – JBernardo
請在這裏輸入這些東西到谷歌之前,python文檔命中1並有正確的答案。 爲了記錄答案是'thestring.lower()' – Serdalis