我正在学习关于codecademy的python课程,并试图创建一个python函数,该函数删除字符串中的元音并返回新修改的字符串。但是,该函数返回字符串时没有任何修改(即,如果我调用anti-u元音(“abcd”),则返回“abcd”)。
在使用print语句之后,for循环似乎只运行一次,而与字符串的长度无关。
def anti_vowel(string):
for t in string:
if(t.lower()=='a' or t.lower()=='e' or t.lower()=='i' or t.lower()=='u'):
string.replace(t, " ")
print "test"
print string
return string