Remove Consonants

Remove all consonants from string.

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

Output

Enter a string: Hello World
Without consonants: eo o

What's going on

Keep only vowels and non-alphabetic characters.

Key Concepts:

Keep vowels
Keep non-alphabetic characters
Remove consonants