Python program to count lower case letters in a string
( 48 Articles)

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
Futher reading:
- Python 3: Convert Datetime to Timestamp and vice versa
- How to run Python 3 with Nodemon on Mac
- Python: Categorizing Given Words by Their First Letters
- Python reduce() function examples
- How to Check Whether an Object is Iterable in Python 3
You can also check out our Machine Learning category page or Python category page for more tutorials and examples.
Subscribe
0 Comments