I want to replace every character that isn’t “i” in the string “aeiou” with a “!”
I wrote:
def changeWord(word):
for letter in word:
if letter != "i":
word.replace(letter,"!")
return word
This just returns the original. How can I return “!!i!!”?
Strings in Python are immutable, so you cannot change them in place. Check out the documentation of str.replace:
So to make it work, do this: