在Python中,可以使用字符串的lower()
方法将字符串转换为小写,并使用rstrip()
方法删除字符串结尾的空格。然后,可以使用字符串的replace()
方法将所有空格替换为多个空格。
以下是一个示例代码:
text = "Don't discriminate between upper and lower case. replace trailing spaces with multiple spaces. "
# 转换为小写并删除结尾的空格
text = text.lower().rstrip()
# 将所有空格替换为多个空格
text = text.replace(" ", " ")
print(text)
输出结果为:
don't discriminate between upper and lower case. replace trailing spaces with multiple spaces.