Python program to count lower case letters in a string

Last updated on November 4, 2020 Guest Contributor Loading... Post a comment

To check if a letter is lower case or not in Python, we can use the islower() method. Combine it with a for loop, we can easily count the number of lower case letters in a given string.

The code:

# the function that counts the number of lower case letters
def myCounter(input):
  total = 0
  for letter in input:
    if(letter.islower()):
      total = total + 1
  return total 

# Initializing dummy strings
s1 = 'A B c d e f G h'
s2 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nunc ligula, egestas at nunc vitae, tincidunt eleifend dui.'

# Try it
print(myCounter(s1))
print(myCounter(s2))

Output:

5
96
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles