Python Practice › String Programs › Program 32

Count vowels

EasyString Programs · 32 of 106

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

Advertisement
Input
"I am learning python"
Output
6

Approach

  1. Count characters that are in “aeiou”, ignoring case.

Solution

Python
text = "I am learning python"print(sum(1 for ch in text.lower() if ch in "aeiou"))
Output
6
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs