python 字符串 islower() 方法用于检查字符串是否包含小写。 如果输入字符串中的所有大小写字符都是小写的,并且至少有一个大小写字符,则此方法返回 true。 否则,它将返回 false。
让我们在下一节中更详细地研究这种方法。
语法
以下是 python 字符串 islower() 方法的语法 -
str.islower()
参数
python 字符串 islower() 方法不包含任何参数。
返回值
如果字符串中的所有大小写字符都是小写的,并且 python 字符串 islower() 方法返回 true 至少是一个大小写字符,否则为 false。
例以下是 python 字符串 islower() 方法的示例。在这个程序中,字符串 “Hello!Welcome to qikepu!“,并调用 islower() 方法来检查创建的字符串中是否存在所有字符都是小写的。使用 print() 方法获取和打印结果输出。
str = "Hello! Welcome to qikepu!";
result=str.islower()
print("Are all the cased characters in the string lowercases?", result)
在执行上述程序时,将生成以下输出 -
Are all the cased characters in the string lowercases? False
例
如果创建的字符串 “Hello!Welcome to qikepu“中,python 字符串 islower() 方法 仅检查大小写字符并相应地返回结果。
str = "welcome to qikepu";
result=str.islower()
print("Are all the cased characters in the string lowercases?", result)
以下是执行上述程序得到的输出 -
Are all the cased characters of the string lowercases? True
例
无论创建的字符串 “Welcome_to_qikepu!” 包含哪些其他字符,如果大小写字符为小写,则 islower() 方法返回 true。
str = "welcome_to_qikepu!";
result=str.islower()
print("Are all the cased characters in the string lowercases?", result)
通过执行上述程序获得以下输出 -
Are all the cased characters of the string lowercases? True
例
无论创建的字符串 “Welcome123” 包含哪些其他字符,如果大小写字符为小写,则 islower() 方法返回 true。
str = "welcome123";
result=str.islower()
print("Are all the cased characters in the string lowercases?", result)
上述程序在执行时显示以下输出 -
Are all the cased characters of the string lowercases? True
例
如果创建的字符串为空或仅包含空格,则 islower() 方法返回 false。
str = "";
result=str.islower()
print("Are all the cased characters in the string lowercases?", result)
上述程序的输出显示如下 -
Are all the cased characters of the string lowercases? False