Since all the other answers completely rewrite the code I figured you'd like one with your code, only slightly modified. Also, I kept it simple, since you're a beginner.
A side note: because you reassign res
to word
in every for loop, you'll only get the last vowel replaced. Instead replace the vowels directly in word
def removeVowels(word):
vowels = ('a', 'e', 'i', 'o', 'u')
for c in word:
if c.lower() in vowels:
word = word.replace(c,"")
return word
Explanation: I just changed if c in vowels:
to if c.lower() in vowels:
.lower()
convert a string to lowercase. So it converted each letter to lowercase, then checked the letter to see if it was in the tuple of vowels, and then replaced it if it was.
The other answers are all good ones, so you should check out the methods they use if you don't know them yet.
Hope this helps!