python 去除所有的中文 英文标点符号
生活随笔
收集整理的這篇文章主要介紹了
python 去除所有的中文 英文标点符号
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
去除英文標點符號
python的string模塊下的 punctuation 包含所有的英文標點符號,所以用replace()一下就可以去除。
代碼示例:
import string stri = 'today is friday, so happy..!!!' punctuation_string = string.punctuationprint("所有的英文標點符號:", punctuation_string) for i in punctuation_string:stri = stri.replace(i, '') print(stri)結果:
所有的英文標點符號: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ today is friday so happy注意:
string.punctuation中的標點符號只有英文
去除中文標點符號:
如果是中文文本,可以調用zhon包的zhon.hanzi.punctuation函數即可得到中文的標點符號集合。
代碼示例:
from zhon.hanzi import punctuationstr = '今天周五,下班了,好開心呀!!' punctuation_str = punctuation print("中文標點符合:", punctuation_str) for i in punctuation:str = str.replace(i, '') print(str)結果:
中文標點符合: "#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、 、〃〈〉《》「」『』【】〔〕〖〗?????〝〞????–—‘’?“”??…?﹏﹑﹔·!?。。 今天周五下班了好開心呀參考博客:python之去除文本標點符號
總結
以上是生活随笔為你收集整理的python 去除所有的中文 英文标点符号的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SOX 音频处理工具基本使用
- 下一篇: Linux下查看系统配置