The string Module
The string module defines constants and variables for processing string objects. See also the
section Strings for a discussion of the string
template substitution and formatting tools Template and Formatter defined in this module.
Module Functions and Classes
As of Python 2.0, most functions in this module are also
available as methods of string objects, and method-based calls are preferred and are more efficient.
See the section Strings for more details and a list
of all available string methods not repeated here. Only items unique
to the string module are listed in
this section.
capwords(s)Split the argument into words using
split, capitalize each word usingcapitalize, and join the capitalized words usingjoin. Replaces runs of whitespace characters by a single space, and removes leading and trailing whitespace.maketrans(from, to)Returns a translation table suitable for passing to
bytes.translate, that will map each character infrominto the character at the same position into;fromandtomust have the same length.FormatterClass that allows creation of custom formatters using the same mechanism as the
str.format()method described in section Strings.TemplateString template substitution class (see the section Strings).
Constants
ascii_lettersThe string
ascii_lowercase + ascii_uppercase.ascii_lowercaseThe string
'abcdefghijklmnopqrstuvwxyz'; not locale-dependent and will not change.ascii_uppercaseThe string
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; not locale-dependent and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access