📜  Python字符串 islower() 方法

📅  最后修改于: 2022-05-13 01:54:18.783000             🧑  作者: Mango

Python字符串 islower() 方法

Python String islower() 方法检查字符串中的所有字符是否都是小写。如果字符串中的所有字母都是小写字母,则此方法返回True 。如果字符串包含至少一个大写字母,则返回 False。

示例 1:演示 islower() 的工作原理

Python3
# 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()))


Python3
# 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))


输出:

Is geeksforgeeks full lower ? : True
Is Geeksforgeeks full lower ? : False

示例 2:实际应用

这个函数可以有多种使用方式,有很多实际应用。一种这样的应用是检查小写,检查专有名词,检查需要所有小写的句子的正确性。下面演示的是一个小例子,展示了 islower() 方法的应用。

Python3

# 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