The islower() method is a built-in string method in Python that is used to check whether all the characters in a string are lowercase. It returns True if all the characters are lowercase, and False otherwise.
Syntax:
string.islower()
How to use the islower() method:
string1 = "hello world"
print(string1.islower()) # True
string2 = "Hello world"
print(string2.islower()) # False
string3 = "123abc"
print(string3.islower()) # True
string4 = "ABC"
print(string4.islower()) # False
Example 1
Checking if a String Contains Lowercase Letters.
string1 = "Hello World"
string2 = "hello world"
if string1.islower():
print("string1 contains only lowercase letters.")
else:
print("string1 contains uppercase letters or a mix of uppercase and lowercase letters.")
if string2.islower():
print("string2 contains only lowercase letters.")
else:
print("string2 contains uppercase letters or a mix of uppercase and lowercase letters.")
Example 2
Converting a String to Lowercase.
string = "Hello World"
if string.islower():
print("The string is already in lowercase.")
else:
string = string.lower()
print("Converted string:", string)
Example 3
Filtering a List of Strings.
words = ["hello", "WORLD", "Python", "news"]
lowercase_words = [word for word in words if word.islower()]
print("Lowercase words:", lowercase_words)