Skip to content

Computer Science · Ch 7 — Functions

Python Standard Library

7.5

Python Standard Library

Python comes with a very extensive standard library — a large collection of ready-made functionality that can be called in a program as and when required. Instead of writing commonly needed functions from scratch every time, the programmer simply uses the library, saving considerable time and effort.

The standard library supplies this functionality in two forms, each covered in its own sub-section:

  • Built-in functions (Section 7.5.1) — ready-made functions such as input(), print(), int(), len() and abs() that are always available and can be called directly, with no extra steps.
  • Modules (Section 7.5.2) — groupings of related functions (such as math, random and statistics) stored as Python files, which must first be brought into the program with an import statement before their functions can be used. …
Figure 7.7Types of functions
Fig. 7.7 — Types of functions

Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your textbook's own diagram.

Figure 7.7 is a tree diagram of five boxes giving the complete family tree of functions in Python.

On the left, a box labelled Function is the root. It connects to two boxes: Standard Library and User Defined. The Standard Library box branches further into two boxes of its own: Built-in and Module.

Reading the tree top-down gives the chapter's whole classification in one glance:

  • Every function is either supplied by Python's standard library or is user defined — written by the programmer for his or her own requirement (Section 7.3).
  • Standard-library functions come in two forms: built-in functions such as input(), print() and len(), which are always available and are called directly with no preparation (Section 7.5.1); and functions grouped inside modules such as math, random and statistics, which must first be brought into the program with an import (or from ... import ...) statement before use (Section 7.5.2). …