【456】python string 类内容(去除文本标点)
repr() 函数可以将对象转为 string 类型。
主要用于 NLP 处理,里面存在一些常量列表,包括数字、字母、大写字母、小写字母、标点符号、空格等。
参考:6.1. string — Common string operations
可以用于删除文本中的标点符号,将标点符号 replace 为 空。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | >>> 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_letters
-
The concatenation of the ascii_lowercase and ascii_uppercase constants described below. This value is not locale-dependent.
- string.ascii_lowercase
-
The lowercase letters 'abcdefghijklmnopqrstuvwxyz'. This value is not locale-dependent and will not change.
- string.ascii_uppercase
-
The uppercase letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. This value is not locale-dependent and will not change.
- string.digits
-
The string '0123456789'.
- string.hexdigits
-
The string '0123456789abcdefABCDEF'.
- string.octdigits
-
The string '01234567'.
- string.punctuation
-
String of ASCII characters which are considered punctuation characters in the C locale.
- string.printable
-
String of ASCII characters which are considered printable. This is a combination of digits, ascii_letters, punctuation, and whitespace.
- string.whitespace
-
A string containing all ASCII characters that are considered whitespace. This includes the characters space, tab, linefeed, return, formfeed, and vertical tab.
posted on 2020-02-07 17:36 McDelfino 阅读(1173) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)