Python – Print different vowels present in a String

By | 2018-04-25T02:41:25+00:00 April 25th, 2018|Python|0 Comments

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:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment