Remove vowels from a string in Python

In this tutorial, we will talk about How to remove vowels from string in Python. So in order to understand the code first, we need to understand what is a string.

What is a String?

A string is a sequence of characters. Strings are immutable (once defined, it cannot be changed). Strings are either surround by single quotation or double quotation. ( ‘  ‘ or ”   “).

String Methods in Python

  • isalnum() – if all characters in a string is numeric.
  • isalpha()- if all characters in a string is alphabet.
  • isupper() – if all characters in a string is in upper case.
  • islower() – if all characters in a string is in lower case.
  • swapcase() – converts lower case to upper case or lower case to upper case.

Basic program of string

String1 = "Hello "

Remove vowels from String in Python

string = input("Enter any string: ")
if string == 'x':
    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:");

Run this code online

In the above code in order to remove all vowels present in a string enter any string having vowel in it. Lets take x as string without a vowel if there is no vowel in the string the code will automatically exit but if there is a vowel in the string (‘a’,’e’,’i’,’o’,’u’)  it will remove all the vowels present in the string and will print new string (newstr) having no vowels in it.

Also learn:

13 responses to “Remove vowels from a string in Python”

  1. Confused says:

    what does “.lower” in “string.lower()” do there?

    • Ambuj Verma says:

      It changes every upper case alphabet into lower case.
      s = ‘XYZ’
      s.lower() returns ‘xyz’
      s= ‘XYZ’
      s = s.lower()
      > xyz
      like this

    • Ambuj Verma says:

      s= ‘XYZ’
      s = s.lower()
      >> xyz
      .lower() change every upper case alphabet into lower case.

  2. Om says:

    but what if i want to remove both upper case and lower case vowels, and not just the lowercase,how can i do that?

  3. Ja Mata says:

    That explanation is bad I think.

    If the input is exactly “x” it EXITS the program.

    If the string is anything else it runs the routine:
    Makes all upper case lower case
    Checks for vowels
    Substitutes a empty blank for any vowel in the string
    Outputs what part(s) of the string that is not a vowel.

  4. Chanchal Sarkar says:

    str = input(“Enter any string: “)
    newstr = str.lower() # Convert all charcters into Lowercase
    vowels = (‘a’, ‘e’, ‘i’, ‘o’, ‘u’) # vowels as Tuples
    for i in str.lower():
    if i in vowels:
    newstr = newstr.replace(i, “”) # Replaced by no balank spaces
    print(“New string after successfully removed all the vowels: “)

  5. S. Vinutha says:

    is it necessary that we have to write lower in the program

  6. Chukwudi says:

    Won’t work. Strings are immutable. first convert string to list, carry out your process and convert back to string.

  7. Ehsan Razi KM says:

    s= input()
    for x in s:
    if x in vowels:
    print (new_s)

  8. girish pal says:

    new_s = s
    for x in s :
    if x in ‘aeiouAEIOU’:
    new_s = new_s.replace(x,””)

  9. Pavan Sai says:

    Capital letters are not removing.
    Example: Once upon a time
    Output: Onc pn tm
    I want to remove “Upper Case” letters also.

    • Saruque Ahamed Mollick says:

      Kindly remove that line : for x in string.lower():
      And add capital letters too in this list: vowels = (‘a’, ‘e’, ‘i’, ‘o’, ‘u’);
      It will work fine

Leave a Reply

Your email address will not be published. Required fields are marked *