python一次去掉所有标点符号

既然是一次性去掉所有的标点符号,那当然是用正则表达式啦:

import re
 
punctuation = '!,;:?"\''
def removePunctuation(text):
    text = re.sub(r'[{}]+'.format(punctuation),'',text)
    return text.strip().lower()
 
text = " Hello, world!  "
print removePunctuation(text)

猜你喜欢

转载自blog.csdn.net/Dongfnag_HU/article/details/85076819