Python Count the Number of Vowels In a String: A Completed Guide – Python String Tutorial

By | April 5, 2020

We can count the number of vowels in a string easily in python, it can help us to analysis text for nlp problem. In this tutorial, we will use a simple example to show you how to count.

What are vowels?

In english, letters – a, e, i, o, u are vowels, we can count the total number of these lettes in a string.

Way to count the total number of vowels.

Create python string and vowels

text = 'https://www.tutorialexample.com'

vowels = ['a', 'e', 'i', 'o', 'u']

Here we save vowels in a python list.

Count the total number of vowels in a pyhon string

total_count = 0

text = text.lower()
for w in vowels:
    total_count += text.count(w)
        
print(total_count)

Here we use python string count() function to count the total times of each vowel in python string.

Python String count(): Return the Times Substring in String – Python Tutorial

Run this code, you will get the total number is: 8

Leave a Reply