Python去除所有中英文标点

Posted 兔子爱读书

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python去除所有中英文标点相关的知识,希望对你有一定的参考价值。

string.punctuation支持导入所有英文标点:

!"#$%&’()*+,-./:;<=>?@[]^_`{|}~

zhon.hanzi.punctuation支持导入所有中文标点:

"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、 、〃〈〉《》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏﹑﹔·!?。。

import re
from string import punctuation as punctuation_en 
from zhon.hanzi import punctuation as punctuation_zh 

print("去除所有的英文标点符号:", punctuation_en)    
a = "I am so happy!!! Oh yes~"
b = re.sub("[{}]+".format(punctuation_en), "", a) 
print(b)

print("去除所有的中文标点符号:", punctuation_zh)    
c = "你真是太帅了!!要继续加油哦~"
d = re.sub("[{}]+".format(punctuation_zh), "", c) 
print(d)

以上是关于Python去除所有中英文标点的主要内容,如果未能解决你的问题,请参考以下文章

Python去除所有中英文标点

python正则表达式去除所有标点

去除文本中标点符号的java程序

python中用正则表达式去掉文本中所有的标点符号

Python使用jieba库分词并去除标点符号

456python string 类内容(去除文本标点)