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 using capitalize, and join the capitalized words using join. 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 in from into the character at the same position in to; from and to must have the same length.

Formatter

Class that allows creation of custom formatters using the same mechanism as the str.format() method described in section Strings.

Template

String template substitution class (see the section Strings).

Constants

ascii_letters

The string ascii_lowercase + ascii_uppercase.

ascii_lowercase

The string 'abcdefghijklmnopqrstuvwxyz'; not locale-dependent and will not change.

ascii_uppercase

The string 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; not locale-dependent and ...

Get Python Pocket Reference, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.