初级Python:为字符串指定字符

2024-10-06 11:17:17 发布

您现在位置:Python中文网/ 问答频道 /正文

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

为什么打印的是“ee2ee”,而不是“22222”?你知道吗

我说,每当“e”出现时,就换成“2”。你知道吗

我真的不明白。你知道吗


Tags: textinforreturnifdefprintanti
1条回答
网友
1楼 · 发布于 2024-10-06 11:17:17

通过将字符连续复制到c中,可以循环text
你只会改变c。你知道吗

c = "2"

在返回它之前,没有任何东西会改变text。你知道吗

相关问题 更多 >