Library Modules
Currently, there are more than 200 modules in the standard distribution, covering topics such as string and text processing, networking and web tools, system interfaces, database interfaces, serialization, data structures and algorithms, user interfaces, numerical computing, and others. We touch on only the most widely used here and mention some of the more powerful and specialized ones in Chapter 9, and Chapter 10.
Basic String Operations: The string Module
The
string module is
somewhat of a historical anomaly. If Python were being designed
today, chances are many functions currently in the
string module would be implemented instead as
methods of string objects.[57]
The
string module operates on strings. Table 8.4 lists the most useful functions defined in the
string module, along with brief descriptions, just
to give you an idea as to the module’s purpose. The
descriptions given here are not complete; for an exhaustive listing,
check the Library Reference or the
Python Pocket Reference. Except when otherwise
noted, each function returns a string.
Table 8-4. String Module Functions
|
Function Name |
Behavior |
|---|---|
atof(
|
Converts a string to a floating point number (see the
>>>
|
atoi( |
Converts a string to an integer, using the base specified (base 10 by
default (see the >>>
|
atol( |
Same as |
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