The Standard Library Tour
Discover the powerful tools that come built-in with every Python installation.
Learning Objectives
- Understand what the Standard Library is
- Explore the 'sys' module for system tasks
- Explore the 'statistics' module
- Learn about the 'collections' module (Counter)
Batteries Included
Python is often described as having “batteries included”. This means that it comes with a large set of pre-written code called the Standard Library. You’ve already used math, random, and json. Today, we look at a few more.
The sys Module
Use this to interact with the Python runtime environment itself.
|
|
The statistics Module
Perfect for simple data analysis without needing complex external tools.
|
|
The collections Module
Provides specialized “container” data types. Counter is one of the most useful.
|
|
Why learn these?
Knowing what’s in the Standard Library prevents you from “reinventing the wheel”. Before writing a complex loop to count items or calculate an average, check if Python already has a battery for it!
Interactive Practice
Explore the time module. Can you use time.sleep(2) to make your program wait for 2 seconds before printing a message?
| Module | Battery For… |
|---|---|
| sys | System paths and arguments |
| statistics | Basic math analysis |
| collections | Specialized lists/dicts |
| itertools | Complex loops and iterations |
Quiz
Complete this quiz with a minimum score of 80% to mark Day 26 as complete.
Discussion
Have questions or want to discuss this lesson? Join the conversation below!