Python String islower() Method
The str.islower()
method returns True
if all the characters in a string are in lowercase. If it finds at least one of the characters in uppercase, it returns False
.
Example:
text ="python is awesome"
print(text.islower())
Output
True
Syntax
The Syntax of the str.islower()
function is:
str.islower()
Here, str
is a string.
Parameters
The str.islower()
function does not take any parameters.
Return Value
The str.islower()
function returns:
True
if all the characters in the string are in lowercaseFalse
if at least one of the characters in the string is in uppercase
Example 1: Python Program to check if the string is in lowercase
The lower()
method returns:
True
: If all the characters in the string is lowercaseTrue
: If the string has a combination of numbers and lowercase charactersTrue
: If the string has a combination of numbers, special case, and lowercase charactersFalse
: If the string has one or more uppercase characterFalse
: If the string has only whitespace or numbers
# lowercase string
text ="python"
print(text.islower())
# string with numbers
text ="python3 is released in the year 2008"
print(text.islower())
# string with special chars
text ="https://www.python.org"
print(text.islower())
# titlecase string
text ="Python"
print(text.islower())
# Uppercase string
text ="PYTHON"
print(text.islower())
# Mixed Case string
text ="Welcome To Python Tutorial"
print(text.islower())
# String with only numbers
text ="2022"
print(text.islower())
Output
True
True
True
False
False
False
False
Example 2: How to use islower() function in a Program?
In the real-world use case, we can use islower()
method to check if the given string consists of only lowercase characters. Here are a few examples where lowercase strings are preferred:
- Checking Email Address
- Verifying username
- Domain Names
# Method to verify if the text is lower
def check_lower(text):
if text.islower() == True:
return "All the characters in the sentence are in lowercase"
else:
return "one or more characters in the sentence are not in lowercase"
# All characters are in lowercase
print(check_lower("there are seven continents in the world."))
# some characters are in uppercase
print(check_lower("There are Seven Continents in the World."))
Output
All the characters in the sentence are in lowercase
one or more characters in the sentence are not in lowercase
Reference: Python Official String Methods