当前位置:首页 » 编程语言 » python去除标点符号

python去除标点符号

发布时间: 2022-04-18 19:22:33

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

你应该先定义变量 punctuation,其内容应该是所有的标点符号,比如下面的代码 (我没有列出所有的标点)

importre

punctuation='!,;:?"''
defremovePunctuation(text):
text=re.sub(r'[{}]+'.format(punctuation),'',text)
returntext.strip().lower()

text="Hello,world!"
printremovePunctuation(text)

2. python中删除字符串中某个字符

删除字符串中某个字符的时候,可以直接点击删除按钮,或者是理理解按键。

3. python去除字符串中的标点符号

str = "hello,python。"
print(str.replace(",", ""))

4. python 里面怎么把list里面的string的标点符号去掉

假设你要从string中删除‘a’字符,那么可以尝试如下代码:

myList=['abcde','acedfh','sddibadfa']
newList=[myL.replace('a','')formyLinmyList]
printnewList

其他字符同理

以上!!!

5. python如何删除文本中连续的标点符号啊

defget_solo(text):
els=[x+xforxinlist('。,!')]
#如需增加标点符号,比如问号,直接将list('。,!')换成list('。,!?')即可.
fordinels:
whiledintext:
text=text.replace(d,d[0])
returntext

if__name__=='__main__':
text='开开心心,,,,上上。。。好好的!!'
print(get_solo(text))

结果:

>>>
开开心心,上上。好好的!

6. python中怎么使用正则表达式将txt文档中的标点符号过滤并且导出

标点符号有很多种,也许可以用\W来表示,或者[.。, ]之类的列表

7. python正则表达式去除所有符号

importre
a='asdas,ad,ad.adasd,adq,eqasdad!adas@asd#asdsa$adasd%adsa&asd'
printre.sub('[^a-zA-Z0-9]',"",a)

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

我的理解是 python’s的“ ’ ”也是字符 ,和标点符号一样。你只要把去除的字符都加到正则表达式的括号中就可以了。,所以:

import re

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

line=re.sub(r,'',"python’s")

print line

9. python 怎么去掉标点符号

用下面这串代码即可去掉标点符号

importstring

m=l.translate(None,string.punctuation)

10. python 字符串过滤英文标点符号

import unicodedata
import sys

tbl = dict.fromkeys(i for i in xrange(sys.maxunicode)
if unicodedata.category(unichr(i)).startswith('P'))
def remove_punctuation(text):
return text.translate(tbl)

import regex as re

def remove_punctuation(text):
return re.sub(ur"\p{P}+", "", text)

热点内容
安卓系统date什么意思 发布:2025-07-01 07:58:06 浏览:480
linuxtr 发布:2025-07-01 07:57:59 浏览:656
假装编程 发布:2025-07-01 07:39:44 浏览:213
python项目开发实例 发布:2025-07-01 07:39:44 浏览:63
php字符串截取中文 发布:2025-07-01 07:26:46 浏览:436
8266连接阿里云服务器 发布:2025-07-01 07:23:38 浏览:4
php提交方式 发布:2025-07-01 07:23:36 浏览:355
对java理解 发布:2025-07-01 07:22:16 浏览:911
我的世界逆编译 发布:2025-07-01 07:12:14 浏览:772
ssd英特尔快速存储技术 发布:2025-07-01 07:07:11 浏览:227