Computer Science · Ch 7 — Functions
Python Standard Library
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()andabs()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,randomandstatistics) stored as Python files, which must first be brought into the program with animportstatement before their functions can be used. …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your NCERT 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()andlen(), which are always available and are called directly with no preparation (Section 7.5.1); and functions grouped inside modules such asmath,randomandstatistics, which must first be brought into the program with animport(orfrom ... import ...) statement before use (Section 7.5.2). …