string.lower()函数是Python中的一个字符串函数,它可以将字符串中的所有字母转换为小写字母。它的使用方法也非常简单:只需要在字符串变量后面加上.lower()即可。例如:
string = "HELLO WORLD" string.lower()
执行上述代码后,string变量的值就会变成"hello world",所有大写字母都会变成小写字母。
string.lower()函数还可以用来比较字符串大小,例如:
string1 = "hello" string2 = "Hello" if string1.lower() == string2.lower(): print("The two strings are equal") else: print("The two strings are not equal")
上述代码会输出“The two strings are equal”,因为string1和string2被转换成了小写字母,它们的值实际上是相等的。
string.lower()函数是一个非常实用的字符串函数,它可以帮助我们轻松地将字符串中的字母转换为小写字母,也可以用来比较字符串大小。