9 月 252020
#自定义函数,敏感词删剪
#指定参数censored_word和changed_word默认值
def text_filter(word, censored_word = 'lame', changed_word = 'Awesome'):
#替换word中匹配的censored_word为changed_word
#返回replace()处理后的结果
return word.replace(censored_word, changed_word)
#调用函数,只传入参数word,函数返回对参数word的替换操作后内容
print(text_filter('Python is lame!'))
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
Python is Awesome!
PS C:\Users\harveymei>