如何将大写字母转换为小写字母

2024-04-19 17:13:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个脚本,它读取输入并列出它,但我想它转换大写字母到小写字母,我如何能做到这一点?

这就是我得到的

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

Tags: textin脚本forifline大写字母sentence
3条回答

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

list.append(sentence.lower())

我在搜索“python upper to lower case”后的第一个结果中找到了这个。

您可以在文档的5.6.1. String Methods部分找到更多与Python字符串相关的方法和函数。

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

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

相关问题 更多 >