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> 

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据