The string Module and Methods
The string
module defines constants and variables
for processing string objects, above and beyond string type
operations. See also string built-in type operations and
string-related built-in functions in Section 1.6, and Section 1.19.
Module Functions Versus String Object Methods
As of Python 2.0, most functions in this module are also available as
methods of string objects (see Section 1.6.2 in Section 1.6 for more
details and a list of all available string methods). A
string
module function call such as
func(str,
arg)
is generally now
also accessible as str.func(arg)
. Where
appropriate, both call formats are listed.
Note that as of Python 2.2, much of the string
module is available as object methods, but not all; constants and
some module functions are still available only in the
string
module. Function entries with just one
listed call signature are not available as string methods. Similarly,
some string methods are not available in this module (see the string
type in Section 1.6).
Constants
digits
The string
'0123456789'
.hexdigits
The string
'0123456789abcdefABCDEF'
.letters
Concatenation of the strings
lowercase
anduppercase
.lowercase
Usually, the string
'abcdefghijklmnopqrstuvwxyz'
.[10]octdigits
The string
'01234567'
.printable
Combination of
digits
,letters
,punctuation
, andwhitespace
.punctuation
String of characters that are considered punctuation characters.
uppercase
Usually,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
.whitespace
String containing space, tab, linefeed, ...
Get Python Pocket Reference, Second 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.