Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Remove Vowels

Remove English vowel characters from text with a loop. Students build a new result from nonmatches and preserve spaces, punctuation, and remaining letter order.

IntermediatePhase 5 - Category 2: Character OperationsExample 9 of 10
remove-vowels.py
1# Take string input
2s = input("Enter a string: ")
3
4# Remove vowels
5vowels = "aeiouAEIOU"
6result = ""
7for char in s:
8 if char not in vowels:
9 result += char
10
11print(f"Without vowels: {result}")

Output

Enter a string: Hello
Without vowels: Hll

In this one

  • Filter a listed character set
  • Keep nonvowels in order
  • Retain punctuation and spaces

How it works

  1. 1

    Visit the input's characters.

  2. 2

    Append char only when absent from vowels.

  3. 3

    Print the new filtered string.

Edge cases

Are spaces removed?

Are spaces removed?

No. They are copied.

What if the input contains only listed vowels?

What if the input contains only listed vowels?

The result is empty.

What's going on

The vowel string contains both English cases. A character is appended only if it is not a member of that string.

For Hello!, the result is Hll!. No lowercase conversion is required because both cases are listed. Digits and spaces remain because they are not vowels. Accented characters and y also remain under this explicit vowel definition.

Are spaces removed? No. They are copied.

What if the input contains only listed vowels? The result is empty.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

What does the condition select?

Pick an answer to check it.

Question 2

Are spaces removed?

Pick an answer to check it.

Questions people ask

Are spaces removed?

No. They are copied.

What if the input contains only listed vowels?

The result is empty.

What does the condition select?

Characters absent from the vowel set.