string 模块:字符串处理
In [1]:
- import string
标点符号:
In [2]:
- string.punctuation
Out[2]:
- '!"#$%&\'()*+,-./:;<=>[email protected][\\]^_`{|}~'
字母表:
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 '