Python Program to Count Number of Lowercase Characters in a String



When it is required to count the number of lowercase characters in a string, the string can be iterated over. It can be checked to see if it has lower case characters, and the counter can be incremented.

Below is the demonstration of the same −

Example

 Live Demo

my_string = "Hi there how are you"
print("The string is :")
print(my_string)
my_counter=0
for i in my_string:
   if(i.islower()):
      my_counter=my_counter+1
print("The number of lowercase characters are :")
print(my_counter)

Output

The string is :
Hi there how are you
The number of lowercase characters are :
15

Explanation

  • A string is defined, and is displayed on the console.

  • A counter is initialized to 0.

  • The string is iterated over.

  • It is checked to see if it is lower case.

  • If it is lower case, the counter is incremented.

  • This is the output that is displayed on the console.


Advertisements