当前位置:首页 » 编程语言 » 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)

热点内容
共享电脑提示服务器内存不足 发布:2025-09-17 11:33:17 浏览:632
python微信公众号 发布:2025-09-17 11:13:10 浏览:545
源码和千锋 发布:2025-09-17 10:58:53 浏览:27
memcache数据库 发布:2025-09-17 10:23:01 浏览:68
安卓机如何锁软件 发布:2025-09-17 10:18:34 浏览:946
二手3系买哪个配置好 发布:2025-09-17 10:07:16 浏览:741
sqlserver2000xp 发布:2025-09-17 09:36:19 浏览:832
c9什么时候升级安卓70 发布:2025-09-17 09:35:36 浏览:214
速算法中 发布:2025-09-17 09:30:50 浏览:383
怎么进网站服务器 发布:2025-09-17 09:18:15 浏览:465