python 初学01

在codecademy上学习python有一段时间。好像持续的时间太长,学习得太零碎,导致记忆不牢。学习之后,应该多少写些。

函数要实现,输入两个字符串,第一个字符串中包含的第二个字符串用*代替,返回第一个字符串。

def censor(text, word):
    temp = text.split(" ")
    result = []
    for str in temp:
        if str == word:
            str = "*" * len(word)
        result.append(str)
    text = ' '.join(result)
    return text
原文地址:https://www.cnblogs.com/itit/p/3749103.html