The string module provides a number of strings constants, as follows:
__all__ = ["Ascii_letters", "Ascii_lowercase", "Ascii_uppercase", "Capwords", "digits", "hexdigits", "Octdigits", "Printable", "punctuation", "whitespace", "Formatter", "Template"]# Some strings for Ctype-style character Classificationwhitespace = ' \t\n\r\v\f ' ascii_lowercase = ' abcdefghijklmnopqrstuvwxyz ' ascii_uppercase = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ ' ascii_letters = ascii_lowercase + ascii_uppercasedigits = ' 0123456789 ' hexdigits = digits + ' ABCdef ' + ' abcdef ' octdigits = ' 01234567 ' punctuation = R ' ""! " #$%& ' () *+,-./:;<=>[email protected][\]^_ ' {|} ~ "" "printable = digits + ascii_letters + punctuation + whitespace
These constants are useful in many situations, such as removing all the letters to the left of the string:
Provides a function capwords, the function prototype is:
def capwords (S, sep=none): return (Sep or "). Join (X.capitalize () for x in S.split (Sep))
There are also two classes: template and Formatter, follow-up study.
Python Module Learning: String Module 1