Python-string类学习
来源:互联网 发布:js调用电脑摄像头拍照 编辑:程序博客网 时间:2024/06/06 06:06
今天在练习一个字符串操作时,需要把大小写字母全部都保存到一个列表中。联想到shell中都有使用POSIX字符类,如[:alnum:]表示字母与数字字符,[:alpha:]表示字母字符, [:digit:]表示数字字符,python作为高级、流行的编程语言,理论上应该有提供类似功能的模块。
仔细查了下,发现string模块刚好符合我需要的功能,该模块包括了以下常量字符集。
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.
这些常量把常用的一些字符集都列举出来了,我们可以根据自己的需要进行选择。
另外,string模块还有一个capwords函数,即把传入的字符串变成首字母大写。
string.capwords("abc,abc,test", sep=",")
'Abc,Abc,Test'
阅读全文
0 0
- Python-string类学习
- Python学习之 string
- python学习string
- python学习--string模块
- python学习笔记 (string)
- python 学习笔记之string
- Python学习-String(一)
- Python学习笔记3-string
- Python学习(二) 字符串String
- python学习string method: find and rfind
- python 系统学习笔记(二)---string
- Python学习笔记--字符串操作string
- python 系统学习笔记(二)---string
- Python中的string模块的学习
- python学习笔记7-- string类型
- python string,Unicode和Qstring学习笔记
- Python中的string模块的学习
- Python中的string模块的学习
- POJ
- Mountain Subsequences(山东省第四届ACM大学生程序设计竞赛)
- php 微信公众号企业转账功能
- 如何在编译Python指定使用自定义安装的openssl
- POJ
- Python-string类学习
- Java的单例模式你真的懂了吗?
- Kafka学习总结(二)——Kafka设计原理
- 训练XGBoost的一些脚本,
- Codeforces 810B Summer sell-off 题解
- 安卓的SMS 短信的增删改查
- 栈的应用---括号匹配问题
- 26-28-29-31.struts2_CRUD操作
- POJ