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 "
 print(String1) 
Output: 
 Hello

Remove vowels from String in Python

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

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:

7 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()
      print(s)
      > xyz
      like this

    • Ambuj Verma says:

      s= ‘XYZ’
      s = s.lower()
      print(s)
      >> 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: “)
    print(newstr)

  5. S. Vinutha says:

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

Leave a Reply

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