Instagram
youtube
Facebook
Twitter

Delete Vowels in a Given String

A Python program to remove all vowels (both uppercase and lowercase) from the input string.

Explanation of Code in Points:

  1. Define Function: delete_vowels(string) → Removes vowels from the input string.
     
  2. Store Vowels: vowels = "aeiouAEIOU" → Contains both lowercase and uppercase vowels.
     
  3. Initialize Empty String: new_string = "" → Stores the modified string without vowels.
     
  4. Loop Through String: for char in string: → Iterates through each character in the input string.
     
  5. Check for Vowels: if char not in vowels: → If the character is not a vowel, add it to new_string.
     
  6. Return Result: return new_string → Returns the string without vowels.
     
  7. Take User Input: string = input("Enter a string: ") → Asks the user to enter a string.
     
  8. Call Function & Store Result: result = delete_vowels(string) → Calls the function and stores the output.
     
  9. Print Final Output: print("String without vowels:", result) → Displays the modified string.

 

Program:

def delete_vowels(string):

    vowels = "aeiouAEIOU"

    new_string = ""

    for char in string:

        if char not in vowels:

            new_string += char  

    return new_string  

string = input("Enter a string: ")

result = delete_vowels(string)

print("String without vowels:", result)