string模块中定义了一些常用的属性(包含所有数字,字母,可打印的所有ascii码等)
print(string.ascii_letters) # 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(string.ascii_lowercase) # 'abcdefghijklmnopqrstuvwxyz'
print(string.ascii_uppercase) # 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(string.digits) # '0123456789'
print(string.hexdigits) # '0123456789abcdefABCDEF'
print(string.octdigits) # '01234567'
print(string.printable) # '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
print(string.punctuation) # '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
print(string.whitespace) # ' \t\n\r\x0b\x0c'
string.capwords(s, sep=None)是多个字符串方法的组合split(),capitalize(),join()
s = 'ahelloaworld'
print(string.capwords(s, 'a'))
等同于
print('a'.join([i.capitalize() for i in s.split('a')]))
结果为:aHelloaWorld