Python 字符串方法

Python str.lower() 方法用于把字符串转成小写

语法

s.lower()

参数

无参数(方法调用在字符串对象上)。

返回值

返回新字符串,全部转为小写。原字符串不变。

示例

s = "Hello World"
print(s.lower())     # hello world

name = "TOM"
if name.lower() == "tom":
    print("匹配!")

print("PYTHON".lower())   # python

输出:

hello world
匹配!
python

注意事项

返回新字符串,原字符串不变。比较用户输入常用"先 lower 再比"实现大小写不敏感。