使用更好的脏话审查Python中的坏词
在本文中,我们将学习如何使用Python审查坏词。为此,我们使用Python中的better_profanity模块。
安装
pip install better_profanity
为了审查坏词,我们使用了来自 Better_profanity 的 profanity.censor() 方法。因此,我们首先讨论它的语法和参数。
Syntax: profanity.censor(text, censor_char=’*’)
Parameters:
text : text to be censor
censor_char : ‘*’ by default, character to censor bad words
Return value: censored text
方法:
- 导入包(脏话)
- 声明或输入要审查的文本。
- 使用 profanity.censor() 方法并获取审查文本。
- 打印经过审查的文本。
示例 1:
Python3
# importing package
from better_profanity import profanity
# text to be censored
text = "What the shit are you doing?"
# do censoring
censored = profanity.censor(text)
# view output
print(censored)
Python3
# importing package
from better_profanity import profanity
# text to be censored
text = "What the shit are you doing?"
# do censoring
censored = profanity.censor(text, '$')
# view output
print(censored)
输出:
What the **** are you doing?
示例 2:
蟒蛇3
# importing package
from better_profanity import profanity
# text to be censored
text = "What the shit are you doing?"
# do censoring
censored = profanity.censor(text, '$')
# view output
print(censored)
输出:
What the $$$$ are you doing?