Python program to count vowels in a string

Description: Write a Python program to count the number of vowels in a string.

Rules and hints:

  • Vowels are a, e, i, o and u.
  • Change the text to lowercase first, so capital letters are counted too.

Python program to count vowels

text = "Tutorials Class"
vowels = "aeiou"
count = 0

for ch in text.lower():
    if ch in vowels:
        count += 1

print("Number of vowels:", count)

Output:

Tutorials Class - Output Window

Number of vowels: 5

How it works

  • The loop checks each character of the text.
  • ch in vowels is True when the character is one of a, e, i, o, u.
  • The vowels in “Tutorials Class” are u, o, i, a and a, so the count is 5.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.