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 will not change.

digits

The string '0123456789'.

hexdigits

The string '0123456789abcdefABCDEF'.

octdigits

The string '01234567'.

printable

Combination of digits, ascii_letters, punctuation, and whitespace.

punctuation

String of characters that are considered punctuation characters in the locale.

whitespace

String containing space, tab, linefeed, return, formfeed, and vertical tab: ' vf'.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset