All TalkersCode Topics

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

Find Vowels In String Python

Last Updated : Mar 11, 2024

Find Vowels In String Python

In this article we will show you the solution of find vowels in string python, to find vowels in a string in Python is similar to a searching method in Data structures and Algorithms. We can perform various actions on a string as per program requirements.

This is not limited to finding vowels or certain characters in a string, we can also find substrings, numbers, alphanumeric combinations, and much more.

All this can be done with simple programming fundamentals, as shown below.

Step By Step Guide On Find Vowels In String Python :-

To find the vowels in a string and print them in Python, we are going to use the built-in lower() function and print() function along with the extra end=" " parameter.

lower() function:

Syntax: str.lower()

Use: The lower() function converts all the characters in a string into lowercase of the alphabet.

print() function:

Syntax: print(object, end=" ")

Use: The print() function prints or displays the output in the console.

The extra 'end' parameter is used to keep the cursor on the same line.

If we pass a space through the 'end' parameter then each print statement's output is separated by a space and not a new line.

Similarly, if we pass forward slash or any other character then the output will be separated by that character.

str1 = 'Python is a dynamic language.'
vowels = ['a', 'e', 'i', 'o', 'u']
for i in str1:
if i.lower() in vowels:
print(i , end=" ")

#Code Output
o i a a i a u a e
  1. A string is defined as str1, the string can also be taken as input from the user.
  2. All the vowels are stored in a list named 'vowels', which can be further used for finding the vowels in the string.
  3. To iterate over every character in a string to check if it's a vowel or not, we will use a 'for-loop'.
  4. During iteration built-in lower() function is used to convert each character into lowercase. As the vowels stored in the 'vowel' list are in lowercase, this increases the simplicity of the program.
  5. Using the if conditional statement, the character is checked to be present in the list of vowels or not.
  6. If the character is present, then it is printed in the console.
  7. In the above code snippet, 'Python is a dynamic language.' is the defined string.
  8. After iterating through the characters in the string. Using an if conditional statement, if the character is a vowel, directly print it.
  9. If the character is a consonant no action is specified so none will be taken.
  10. To make sure that the output is on the same line, the end parameter is used and passed the value of a space.
  11. When the iteration is over, we get all the vowels in a string in Python

Conclusion :-

This is how we can find vowels in a string and print them in Python using built-in functions and loops.

There are other ways too to find the vowels in string in Python, you can try them out.

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

Author Image About Anjali

Experienced Computer Programmer with a broad range of experience in technology. Strengths in application development and Object Oriented architecture design, front end programming, usability and multimedia technology. Expert in coding languages such as C, C++ Java, JavaScript, PHP and more.

Follow Anjali On Linkedin 🡪