python3去掉字符串中的标点符号方法

  

网上看到的python去掉字符串中的标点符号的方法,大多是基于python2的,不适用python3,调整后代码如下:

  

<强>代码

        lower_case_documents=['你好,你好!”、“赢钱赢。”,“现在打电话给我。”,“你好,叫你好你明天# 63;']   sans_punctuation_documents=[]   进口的字符串      因为我在lower_case_documents:   #待办事项   trantab=str.maketrans({关键:没有一个关键在string.punctuation})   j=i.translate (trantab)   sans_punctuation_documents.append (j)      打印(sans_punctuation_documents)      [你好你好,在家赢钱赢了,现在叫我,“明天你好叫你好”)   之前      

<强>参考

  https://stackoverflow.com/questions/265960/best-way-to-strip-punctuation-from-a-string-in-python

  

以上这篇python3去掉字符串中的标点符号方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

python3去掉字符串中的标点符号方法