Python: Remove all vowels from a given string
Python Basic - 1: Exercise-128 with Solution
Write a Python program to remove all vowels from a given string.
Sample Solution-1:
Python Code:
import re
def test(text):
return re.sub(r'[aeiou]+', '', text, flags=re.IGNORECASE)
text = "Python";
print("Original string:",text)
print("After removing all the vowels from the said string: " + test(text))
text = "C Sharp"
print("\nOriginal string:",text)
print("After removing all the vowels from the said string: " + test(text))
text = "JavaScript"
print("\nOriginal string:",text)
print("After removing all the vowels from the said string: " + test(text))
Sample Output:
Original string: Python After removing all the vowels from the said string: Pythn Original string: C Sharp After removing all the vowels from the said string: C Shrp Original string: JavaScript After removing all the vowels from the said string: JvScrpt
Flowchart:

Sample Solution-2:
Python Code:
def test(text):
vowels = "AEIOUaeiou"
return ''.join(el for el in text if not el in vowels)
text = "Python";
print("Original string:",text)
print("After removing all the vowels from the said string: " + test(text))
text = "C Sharp"
print("\nOriginal string:",text)
print("After removing all the vowels from the said string: " + test(text))
text = "JavaScript"
print("\nOriginal string:",text)
print("After removing all the vowels from the said string: " + test(text))
Sample Output:
Original string: Python After removing all the vowels from the said string: Pythn Original string: C Sharp After removing all the vowels from the said string: C Shrp Original string: JavaScript After removing all the vowels from the said string: JvScrpt
Flowchart:

Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to check whether the average value of the elements of a given array of numbers is a whole number or not.
Next: Write a Python program to get the index number of all lower case letters in a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join