The islower()
method in Python is used to check whether all the alphabetic characters in a string are in lowercase. It returns True
if all alphabetic characters in the string are lowercase and there is at least one cased character (i.e., it does not return True
for an empty string). Otherwise, it returns False
.Here's the syntax of the islower()
method:
string.islower()
# Examples of islower() method
string1 = "hello"
string2 = "Hello"
string3 = "hello123"
string4 = "123"
result1 = string1.islower()
result2 = string2.islower()
result3 = string3.islower()
result4 = string4.islower()
print("String 1:", string1)
print("String 2:", string2)
print("String 3:", string3)
print("String 4:", string4)
print("islower() result for String 1:", result1)
print("islower() result for String 2:", result2)
print("islower() result for String 3:", result3)
print("islower() result for String 4:", result4)
String 1: hello
String 2: Hello
String 3: hello123
String 4: 123
islower() result for String 1: True
islower() result for String 2: False
islower() result for String 3: True
islower() result for String 4: False
In this example, string1
and string3
are composed entirely of lowercase alphabetic characters, so islower()
returns True
for both. string2
contains an uppercase character, so it is not entirely lowercase, and islower()
returns False
. string4
does not have any alphabetic characters, so it returns False
as well.
The islower()
method is useful when you want to check if a string is in lowercase, for example, to enforce certain formatting rules or to perform text processing tasks that require lowercase strings.