Python’s standard library is the collection of built-in types, constants, functions, exceptions, and modules distributed with Python. Its “batteries included” approach supplies common functionality without requiring additional installations. section 1.2.4 section 19.1
Use the standard library for common programming tasks, including:
- Manipulating strings, bytes, Unicode text, dates, times, collections, and other data types. section 19.1.1
- Performing mathematical, statistical, decimal, fractional, random, and iterator-based operations. section 19.1.1
- Working with files, filesystems, operating-system services, databases, email, web pages, and internet protocols. section 1.2.4 section 19.6
- Developing, debugging, scheduling, formatting, copying, annotating, and coordinating Python programs. section 19.1 section 19.1.1
A web server without extra installation
Import the built-in HTTP server and serve the current directory with two lines: import http.server http.server.test(HandlerClass=http.server.SimpleHTTPRequestHandler) The required networking and HTTP support is already available in Python. section 1.2.4
Table 19.1 String services modules (view table figure)
| Module |
Description and possible uses |
|---|---|
| string |
Compare with string constants, such as digits or whitespace; format strings (see chapter 6) |
| re |
Search and replace text using regular expressions (see chapter 16) |
| struct |
Interpret bytes as packed binary data and read and write structured data to/from files |
| difflib |
Use helpers for computing deltas, find differences between strings or sequences, and create patches and diff files |
| textwrap |
Wrap and fill text and format text by breaking lines or adding spaces |
Browse representative string-service modules such as re, struct, difflib, and textwrap, with their typical uses. section 19.1.1
Check the standard library before searching for external packages. When required functionality is absent, use external-module tooling such as pip and isolate project dependencies with venv. section 19.1 section 19.6






