Python is a simple and effective programming language, useful for a wide variety of tasks. Here we will learn how to write a program to find all vowels in a Python String. In this example, we are going to find and list all the vowels (a, e, u, etc.) in the given string.
Python Program to check vowels in a string
Following is the program that will find all the vowels in a given string:
How does the program work?
find_vowels() function: This function accepts a string and finds all the vowels in it.
List of vowels: ‘aeiouAEIOU’ is a list of vowels. This list identifies uppercase and lowercase vowels.
Search using for loop: Each character is checked to see if it is a vowel with the help of a for loop. If a vowel is present, it is added to the found_vowels list.
Output: Using the print() function, we display the detected vowels.
After you run this program, it will ask you to enter a string on which you would like to perform this operation of finding vowels.
Once you enter the string, simply press the enter button. All the vowels from that string will be in front of you—
For example
I have entered the string = “Virat Kohli”
And, in result I got = [‘i’, ‘a’, ‘o’, ‘i’]
If you guys are also interested in reading about how to check if string contains only digits then you can checkout my short article.
Conclusion
Using the above program we can easily find all the vowels in any string. This program is made simple and effective by using loops and list comprehensions in Python.