4.6 Python Standard Library

  • You write Python programs by combining functions and classes (that is, custom types) that you create with preexisting functions and classes defined in modules, such as those in the Python Standard Library and other libraries.
  • Avoid “reinventing the wheel.”
  • A module is a file that groups related functions, data and classes.
  • A package groups related modules.
  • The Python Standard Library is provided with the core Python language.
  • Its packages and modules contain capabilities for a wide variety of everyday programming tasks.
Some popular Python Standard Library modules
collections—Data structures beyond lists, tuples, dictionaries and sets.
Cryptography modules—Encrypting data for secure transmission.
csv—Processing comma-separated value files (like those in Excel).
datetime—Date and time manipulations. Also modules time and calendar.
decimal—Fixed-point and floating-point arithmetic, including monetary calculations.
doctest—Embed validation tests and expected results in docstrings for simple unit testing.
gettext and locale—Internationalization and localization modules.
json—JavaScript Object Notation (JSON) processing used with web services and NoSQL document databases.
math—Common math constants and operations.
os—Interacting with the operating system.
profile, pstats, timeit—Performance analysis.
random—Pseudorandom numbers.
re—Regular expressions for pattern matching.
sqlite3—SQLite relational database access.
statistics—Mathematical statistics functions such as mean, median, mode and variance.
string—String processing.
sys—Command-line argument processing; standard input, standard output and standard error streams.
tkinter—Graphical user interfaces (GUIs) and canvas-based graphics.
turtle—Turtle graphics.
webbrowser—For conveniently displaying web pages in Python apps.

©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 4 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.

DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.