# Python program to count the number of vowels using set in a given string

We will count the number of vowels using set in a given string. Let’s say we have the following input −

jackofalltrades


The output should be the following, counting the number of vowels −

65


Count the number of vowels using set in a given string

We will count the number of vowels using set in a give string −

## Example

def vowelFunc(str):
c = 0
# Create a set of vowels
s="aeiouAEIOU"
v = set(s)

# Loop to traverse the alphabet in the given string
for alpha in str:
# If alphabet is present
# in set vowel
if alpha in v:
c = c + 1
print("Count of Vowels = ", c)

# Driver code
str = input("Enter the string = ")
vowelFunc(str)


## Output

Enter the string = howareyou
Count of Vowels = 5


Count the number of vowels using set in a given string without using a function

We will count the number of vowels using set without using a function −

## Example

# string to be checked
myStr = "masterofnone"
count = 0

print("Our String = ",myStr)

# Vowel Set
vowels = set("aeiouAEIOU")

# Loop through, check and count the vowels
for alpha in myStr:
if alpha in vowels:
count += 1
print("Count of Vowels = ",count)


## Output

Our String = masterofnone
Count of Vowels = 5