1 Star 0 Fork 55

zj507071 / AiLearning

forked from OpenDocCN / ailearning 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
147.md 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
布客飞龙 提交于 2020-10-19 21:08 . 2020-10-19 21:08:55

string 模块:字符串处理

In [1]:

import string

标点符号:

In [2]:

string.punctuation

Out[2]:

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

字母表:

In [3]:

print string.letters
print string.ascii_letters
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

小写和大写:

In [4]:

print string.ascii_lowercase
print string.lowercase

print string.ascii_uppercase
print string.uppercase
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ

In [5]:

print string.lower
<function lower at 0x7efda4f2ae60>

数字:

In [6]:

string.digits

Out[6]:

'0123456789'

16 进制数字:

In [7]:

string.hexdigits

Out[7]:

'0123456789abcdefABCDEF'

每个单词的首字符大写:

In [8]:

string.capwords("this is a big world")

Out[8]:

'This Is A Big World'

将指定的单词放到中央:

In [9]:

string.center("test", 20)

Out[9]:

'        test        '
Python
1
https://gitee.com/zj507071/AiLearning.git
git@gitee.com:zj507071/AiLearning.git
zj507071
AiLearning
AiLearning
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891