Python Practice › String Programs › Program 33

Count consonants

EasyString Programs · 33 of 106

Write a Python program to count the consonants in a string.

Advertisement
Input
"sqltools"
Output
6

Approach

  1. A consonant is a letter that is not a vowel.

Solution

Python
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.

More string programs

← All 106 String Programs

Leave a Comment