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
Python Strings
Exercises & Assignments
Python program to check palindrome string
Python program to count vowels in a string
Python program to reverse a string
Interview Questions & Answers
How would you convert a string into lowercase?
How would you convert a string into uppercase?
Why do we use the join() function in Python?
What are f-strings in Python?