菜鸟IT的博客 >> Python
把字符串里去掉英文半角标点符号,去掉中文全角标点符号
# 去除英文标点符号
import string
test1 = 'today is friday, so happy..!!!'
punctuation_en = string.punctuation # punctuation: 标点符号
for i in punctuation_en:
test1 = test1.replace(i, '')
print("测试去掉英文标点",test1)
# 去除中文标点符号, 需要提前按照zhon包
from zhon.hanzi import punctuation
test2 = '今天周五,下班了,好开心呀!!'
for i in punctuation:
test2 = test2.replace(i, '')
print("测试去掉中文标点",test2)
菜鸟IT博客[2022.07.09-11:51] 访问:338