Python program to find the different vowels present in a string.

Print different vowels present in a string:

We can achieve this using in 2  different ways, let’s see both ways.

Example 1:

Traversing each character in a given string and check whether a character is a vowel or not.

elem = input("Enter any statement : ")
vowels =['a','e','i','o','u']
list1=[]
for x in elem:
    if (x in vowels and x not in list1):
        list1.append(x)
print("Vowels present in given statement : ",list1)

Output:

Enter any statement : chandra shekhar goka
Vowels present in given statement :  ['a', 'e', 'o']

Example 2:

We can achieve this functionality using one of the python set function – intersection()

vowels =['a','e','i','o','u']
elem = input("Enter any statement : ")
data = set(elem)
result = data.intersection(vowels)
print("Vowels present in given statement :",result)

Output:

Enter any statement : chandra shekhar
Vowels present in given statement : {'e', 'a'}

Happy Learning 🙂

About the Author:

Founder of onlinetutorialspoint.com Love Java, Python, Shell and opensource frameworks. Follow him on twitter and facebook for latest updates.

Leave A Comment