标签:学习 ssi nta 原型 cas asc ace mat spl
string模块提供了许多字符串常量,如下所示:
__all__ = ["ascii_letters", "ascii_lowercase", "ascii_uppercase", "capwords", "digits", "hexdigits", "octdigits", "printable", "punctuation", "whitespace", "Formatter", "Template"] # Some strings for ctype-style character classification whitespace = ‘ \t\n\r\v\f‘ ascii_lowercase = ‘abcdefghijklmnopqrstuvwxyz‘ ascii_uppercase = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ‘ ascii_letters = ascii_lowercase + ascii_uppercase digits = ‘0123456789‘ hexdigits = digits + ‘abcdef‘ + ‘ABCDEF‘ octdigits = ‘01234567‘ punctuation = r"""!"#$%&‘()*+,-./:;<=>?@[\]^_`{|}~""" printable = digits + ascii_letters + punctuation + whitespace
这些常量在很多场合很有用处,比如要去掉字符串左边的所有字母:
>>> import string >>> a = "asdfjsdnfnfjirrjwoe12345dsf6sdfjksdfj" >>> a.lstrip(string.ascii_letters) ‘12345dsf6sdfjksdfj‘ >>>
提供了一个函数capwords,函数原型为:
def capwords(s, sep=None): return (sep or ‘ ‘).join(x.capitalize() for x in s.split(sep))
还有两个类:Template和Formatter,后续研究。
标签:学习 ssi nta 原型 cas asc ace mat spl
原文地址:https://www.cnblogs.com/luoheng23/p/9490281.html