python如何去除文本标点符号_【456】python string 类内容(去除文本标点)

本文介绍了Python标准库中关于字符串常量处理的相关内容,包括各种预定义的字符串常量如ascii_letters、digits、punctuation等,并展示了如何使用这些常量进行文本处理任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

repr() 函数可以将对象转为 string 类型。

主要用于 NLP 处理,里面存在一些常量列表,包括数字、字母、大写字母、小写字母、标点符号、空格等。

可以用于删除文本中的标点符号,将标点符号 replace 为 空。

>>> import string

>>> string.punctuation

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

>>> string.digits

'0123456789'

>>> string.ascii_letters

'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

>>> string.ascii_lowercase

'abcdefghijklmnopqrstuvwxyz'

>>> string.ascii_uppercase

'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

>>> string.hexdigits

'0123456789abcdefABCDEF'

>>> string.printable

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

>>> string.whitespace

' \t\n\r\x0b\x0c'

6.1.1. String constants

The constants defined in this module are:

string.ascii_lettersThe concatenation of the ascii_lowercase and ascii_uppercase constants described below. This value is not locale-dependent.string.ascii_lowercaseThe lowercase letters 'abcdefghijklmnopqrstuvwxyz'. This value is not locale-dependent and will not change.string.ascii_uppercaseThe uppercase letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. This value is not locale-dependent and will not change.string.digitsThe string '0123456789'.string.hexdigitsThe string '0123456789abcdefABCDEF'.string.octdigitsThe string '01234567'.string.punctuationString of ASCII characters which are considered punctuation characters in the C locale.string.printableString of ASCII characters which are considered printable. This is a combination of digits, ascii_letters, punctuation, and whitespace.string.whitespaceA string containing all ASCII characters that are considered whitespace. This includes the characters space, tab, linefeed, return, formfeed, and vertical tab.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值