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 infrom
into the character at the same position into
;from
andto
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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.