All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

Print Vowels In A String In Python

Last Updated : Mar 11, 2024

Print Vowels In A String In Python

In this article we will show you the solution of print vowels in a string in python, a string is examined to determine how many vowels are present within it and the number of those vowels is displayed.

To accomplish this, there are many methods that can be used. Several popular methods for accomplishing this will be explained in the following article.

Additionally, this accomplishes the same task, but in a slightly different manner.

A dictionary of vowels is formed by ignoring cases through the case fold, and the key is regarded as a vowel in the dictionary.

Using this method of checking and finding the number of vowels in a string is a better and more efficient way to do it.

We will now discuss the idea of a print vowels in a string python with example.

Step By Step Guide On Print Vowels In A String In Python :-

# Python code to count and display number of vowels
# Simply using for and comparing it with a
# string containing all of the vowels
def Check_Vow(string, vowels):
    final = [each for each in string if each in vowels]
# Driver Code
string = "TalkersCode"
vowels = "AaEeIiOoUu"
Check_Vow(string, vowels);
  1. There must be two parameters in the function Check_Vow - a string named "string" and a string containing vowels called "vowels".
  2. A new list named "final" will be created and will contain all the vowels in the given string.
  3. A for loop can cycle through the characters in the provided string one by one.
  4. A simple if statement can be used to determine if the character is a vowel by checking whether it is in a "vowels" string.
  5. Adding a vowel to the final list is the correct action if the current character is a vowel.
  6. In order to display the number of vowels in a given "string", display the length of the "final" list.
  7. In this case, print out the "final" list to show all the vowels contained in the string given.
  8. This step will describe how to define a string called "string" and a string containing vowels called "vowels".
  9. As arguments, pass a string and a list of vowels to the function Check_Vow. By counting the vowels in the string and displaying them, the function produces a list of how many vowels are there.

Conclusion :-

As a result, we have successfully learned to print vowels in string in python.

As you discovered in the article above, Python allows you to count the vowels in a string.

This code does not take upper-case alphabets ('AEIOU') into account since I've only used small-case vowels in these examples ('aeiou').

In order for the upper-case vowels ('AEIOU') to be counted as well, they must be specified separately.

For more efficient results, you can convert the letters to the same case using the lowercase() or uppercase() functions.

I hope this article on print vowels in a string in python helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪