Python Practice › String Programs › Program 33
Count consonants
Write a Python program to count the consonants in a string.
Input
"sqltools"
Output
6
Approach
- A consonant is a letter that is not a vowel.
Solution
text = "sqltools"print(sum(1 for ch in text.lower() if ch.isalpha() and ch not in "aeiou"))Output
6
Learn the concept
New to this topic? Read the lesson, then come back.