In this tutorial, we are going to learn writing python program to remove all vowels present in the string.
For any input string, we have to check whether the string contains vowels or not, if it does then remove the vowels and print the output.
Case1: If the user is given input ‘Quescol’
The output should be ‘Qcsl’
As we know that ‘u’, ‘e’, and ‘o’ are vowels.
Case2: If the user is given input ‘Website’
The output should be ‘Wbst’
As we know that ‘e’, and ‘i’ are vowels
Our logic to remove vowels from the string
- Our program will take any string input from the user.
- Each character of the string will be iterated using ‘for loop’ and checked for the presence of vowels in them using ‘in’ function.
- If vowels are found, replace the character with an empty string and concatenate the rest of the character.
- The result is printed as the output of our program
Algorithm to remove vowels from the string
Step2: Take a string as an input from the user.
Step3: Create an empty string, as result = “ ”
Step4: Use for loop to iterate through the string.
Step5: if vowel found:
i = ‘’
result +=i ( concatenate the characters of string)
Python code to remove vowels from the string
As we can observe, for the input string ‘Quescol’ the output generated is ‘Qscl’. Where the vowels ‘u’, ‘e’, and ‘o’ are removed. While iterating through the string, when vowels were found the vowels were replaced through empty string in line ‘ i= ‘’ ’, and the rest characters were concatenated.