当前位置:首页 » 编程语言 » 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-05-18 04:16:35 浏览:336
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:378
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:612
java用什么软件写 发布:2025-05-18 03:56:19 浏览:32
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:944
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:741
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:803
网卡访问 发布:2025-05-18 03:35:04 浏览:511
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:372