codescracker


python

Python Program to Remove Vowels from String



« Previous Program Next Program »


Remove Vowels from String in Python

To remove all vowels present in a string in python, you have to ask from user to enter a string and start removing all vowels from it. After removing all vowels from that string, print the final string without any vowel as output as shown in the program given below.

Python Programming Code to Remove Vowels from String

Following python program ask from user to enter any string to remove all vowels from that string and then prints that string without any vowel:

# Python Program - Remove Vowels from String

print("Enter 'x' for exit.")
string = input("Enter any string to remove all vowels from it: ")
if string == 'x':
    exit();
else:
    newstr = string;
    print("\nRemoving vowels from the given string...");
    vowels = ('a', 'e', 'i', 'o', 'u');
    for x in string.lower():
        if x in vowels:
            newstr = newstr.replace(x,"");
    print("New string after successfully removed all the vowels:");
    print(newstr);

Here is the sample run of the above python program to illustrates how to remove all vowels from a string:

remove vowels from string python

Above one is the initial output produced after running the program, now you have to supply or enter any string say codescracker that contains some vowels (oeae) to remove all the containing vowels from that given string and print the same string back on output screen but without any vowels, that will be cdscrckr:

delete vowels from string python

Same program on python shell:

python remove vowels from string

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test