Computer >> Computer tutorials >  >> Programming >> Python

How to Count the Number of Vowels in a string using Python?


Declare a string object containing all vowels.

>>> vowels='aeiou'

Set up a count variable initialize to 0

>>> count=0

Check if each character of input string belong to vowel string. If yes increment the count

>>> string='Hello How are you?'
>>> for s in string:
            if s in vowels: count=count+1

In the end display value of count

>>> count
7