本文最后更新于 258 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com
string 模块:字符串处理
import string
标点符号:
string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
字母表:
print string.letters
print string.ascii_letters
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
小写和大写:
print string.ascii_lowercase
print string.lowercase
print string.ascii_uppercase
print string.uppercase
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
print string.lower
数字:
string.digits
'0123456789'
16 进制数字:
string.hexdigits
'0123456789abcdefABCDEF'
每个单词的首字符大写:
string.capwords("this is a big world")
'This Is A Big World'
将指定的单词放到中央:
string.center("test", 20)
' test '