Strings in Python are immutable, so you cannot change them. Check out the str.replace documentation :
Returns a copy of the string with all occurrences of the substring old, replaced by the new one. If the optional argument count is provided, only the first counter instances are replaced.
To make it work, do the following:
def changeWord(word): for letter in word: if letter != "i": word = word.replace(letter,"!") return word
source share