Python string islower method explanation with example

Python string islower() method:

The python string islower* method is used to check if all characters of a string are in lower case or not. This method returns one boolean value based on the characters it contains.

Let’s learn how it works with examples.

Definition of islower():

The islower() method is defined as like below:

str.islower()

We can call this method with any string in Python.

Return value of islower():

The islower() method returns one boolean value. It returns True if all the characters of the string str are in lower case. Else, it returns False.

Parameter of islower():

The islower() method doesn’t take any parameter. It will throw an error if we pass any parameter to it.

Example of islower():

Let’s take an example to check how islower() works:

str_arr = ['hello', 'hello world', 'Hello world',
           'hello123', 'Hello123', 'hello 123']

for str in str_arr:
    print(f'{str} : {str.islower()}')

In this program, str_arr is an array of strings and the for loop is iterating through these strings one by one. For each string, it prints the result of islower(). If you run this program, it will print the output as below:

hello : True
hello world : True
Hello world : False
hello123 : True
Hello123 : False
hello 123 : True
  • For ‘Hello world’, it returns False because the string includes uppercase characters.
  • For ‘Hello123’, it returns False because it includes uppercase characters.
  • For all other strings, it returns True because all the characters are in lowercase.

Example of islower() with user input values:

Let’s write one program that takes one string as an input from the user and prints if it is in lowercase or not.

given_str = input('Enter a string: ')

if given_str.islower():
    print('The characters of this string are in lowercase')
else:
    print('The characters of this string are not in lowercase')

This program takes one string as an input from the user and stores it in the variable given_str. Based on the result of islower() on given_str, it prints a message to the user.

It will give output as below:

Enter a string: Hello World
The characters of this string are not in lowercase

Enter a string: hello world
The characters of this string are in lowercase

Example of python string islower method

You might also like: