Files
30-seconds-of-code/snippets/count_vowels.md
Sarvasv Arora 63c84b7daa Fixed error in code
len() was used twice, which produced error. Fixed that.
Also included print() statements, so that the function call actually prints the no. of vovels.
2019-07-09 21:35:57 +05:30

351 B

count_vowels

Retuns number of vowels in provided string.

Use a regular expression to count the number of vowels (A, E, I, O, U) in a string.

import re


def count_vowels (str):
    return len (re.findall (r '[aeiou]', str, re.IGNORECASE))
`` `

`` `python
print(count_vowels('foobar')) # 3
print(count_vowels('gym'))# 0