Count String Vowels in Python

  • Post category:String

In this article, you will see how to count string vowels in Python. A vowel is a letter that is pronounced with a vowel sound. In English, the vowels are a, e, i, o, u. To count the vowels in a string, you can use the following code.

Step 1: Create a string

str = "CodeAllow"
print("str = ", str)
print("str type = ", type(str))

Step 2: Count string vowels

print("Vowels = ", sum(str.count(vowel) for vowel in "aeiou"))

Output:

str =  CodeAllow
str type =  <class 'str'>
Vowels =  3

Free resources to learn advanced skills: AiHints and CodeAllow