Python Program to Remove Vowels from String

Python Program to Remove Vowels from String

  • To remove all vowels present in a string in Python, you have to ask from use 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.

Source Code:

# 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)





Comments