【发布时间】:2018-07-12 19:23:40
【问题描述】:
def anti_vowel(text):
for c in text:
if c == "e":
c = "2"
return text
print anti_vowel("ee2ee")
为什么打印的是“ee2ee”,而不是“22222”?
我说,只要“e”出来,就换成“2”。
我真的不明白。
【问题讨论】:
-
字符串是不可变的。分配
c = "2"不会更改字符串。 -
即使字符串是可变的,分配
c = "2"仍然不会改变字符串。
标签: python string python-3.x