Python在其库中具有许多实用程序功能,这些功能始终可以帮助我们完成一些日常工作。让我们来看看字符串的工作原理islower()该方法实际上检查字符串中的所有字符是否都为小写。
用法:string.islower()
参数:没有
返回:如果字符串中的所有字母均小写,则为True;如果甚至其中之一为大写,则为False。
代码1:演示islower()的工作
# Python3 code to demonstrate
# working of islower()
# initializing string
islow_str = "geeksforgeeks"
not_islow = "Geeksforgeeks"
# checking which string is
# completely lower
print ("Is geeksforgeeks full lower ?:" + str(islow_str.islower()))
print ("Is Geeksforgeeks full lower ?:" + str(not_islow.islower()))
输出:
Is geeksforgeeks full lower ?:True
Is Geeksforgeeks full lower ?:False
实际应用:此功能可以以多种方式使用,并具有许多实际应用。一种这样的应用是检查小写,检查专有名词,检查要求所有小写的句子的正确性。下面展示的是一个小示例,展示了islower()方法。
代码2:演示islower()方法的实际应用
# Python3 code to demonstrate
# application of islower() method
# checking for proper nouns.
# nouns which start with capital letter
test_str = "Geeksforgeeks is most rated Computer \
Science portal and is highly recommended"
# splitting string
list_str = test_str.split()
count = 0
# counting lower cases
for i in list_str:
if (i.islower()):
count = count + 1
# printing proper nouns count
print ("Number of proper nouns in this sentence is:"
+ str(len(list_str)-count))
输出:
Number of proper nouns in this sentence is:3