0
def anti_vowel(text):
    for c in text:
        if c == "e":
            c = "2"
    return text
print anti_vowel("ee2ee")

Why does this print "ee2ee", not "22222"?

I said, whenever "e" comes out, replace it to "2".

I really can't understand.

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
Arbitrary
  • 148
  • 3
  • 9

1 Answers1

2

You loop over text by making consecutive copies of characters into c.
You only ever change c.

c = "2"

There is nothing which changes text before you return it.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54