How to Write a Python Program to Find All Vowels in a String
Program to find all vowels in a string......
Python is a simple and effective programming language, useful for a wide variety of tasks. Here we will learn how to write a Python program to find all vowels in a string.
In this example, we are going to find and list all the vowels (a, e, i, u, etc.) from 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, as a result, I got = [‘i’, ‘a’, ‘o’, ‘i’].
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.