Anti_vowel only iterates once


Im more interested in why does the loop only iterates once than in the solution itself, since there are many more ways to do so.

def anti_vowel(text):
    for x in text:
        if x in "aeoiuAEOIU":
            text2 = text.replace(x, '') #since strings are immutable
            return text2

It returns “Hy look Words!” when it should return “Hy lk Wrds!”.


The important concept here is that return stops your function.
Inside your loop, you return text2, which means that your function will immediately stop running.


Ooooh thanks, didn’t know return stops the function.