PY-101 ยท Modules and packages
The standard library tour
โฑ 8 min ๐ Real Python 3 ๐ฌ Animated โ Completed
โก The 30-second answer
The standard library is the large set of modules that comes with Python, so you can use them without installing anything. Everyday favourites include datetime for dates, collections for Counter and defaultdict, pathlib for file paths, random, json, csv and itertools. Check it before writing a tool yourself.
- Count with collections.Counter
- Work with dates and timedelta
- Know where to look before reinventing
Try it
Watch it come alive, run it yourself, then prove it. Real Python, right on this page.
Watch Python run the example. Every variable is a jar; watch the values change and the output appear.
from collections import Counterfrom datetime import date, timedeltafrom pathlib import Pathvotes = ["tea", "coffee", "tea", "juice", "tea", "coffee"]print(Counter(votes).most_common(2))due = date(2026, 12, 1) + timedelta(days=45)print("Due:", due)report = Path("reports") / "2026" / "dec.csv"print(report.name, report.suffix, report.parent.name)
Change anything and press Run (or Ctrl+Enter). Then open Watch it and press Watch my code.
Input one line per input() call
Press Run to see the output. Python runs in your browser. Expected output
[('tea', 3), ('coffee', 2)]
Due: 2027-01-15
dec.csv .csv 2026 ๐ฏ Use collections.Counter to print the most common letter in "mississippi" and how often it appears, like: i 4
Input one line per input() call
Press Run to see the output. Python runs in your browser. Need a hint?
letter, count = Counter(word).most_common(1)[0]; print(letter, count)
- The problemYou write 15 lines to count words, then discover Counter does it in one. The standard library is full of those moments; learning what exists saves hours.
- The Python idea
from collections import Counter, defaultdictThe standard library is the large set of modules that comes with Python, so you can use them without installing anything. - In real lifeBilling systems compute due dates with timedelta, and analytics scripts count events with Counter before reaching for bigger libraries.
Start with a question
You write 15 lines to count words, then discover Counter does it in one. The standard library is full of those moments; learning what exists saves hours.
Professional Python leans heavily on the standard library. Knowing it makes your code shorter and more reliable.
Explain it like I'm 10
Python comes with a huge free toolbox already in the house. Before you build a tool, check whether it is already in the box.
The technical explanation
Counter(words).most_common(2) returns the two most frequent items with their counts.
date + timedelta(days=30) does date maths, including month ends and leap years.
Path("reports") / "2026" / "dec.csv" builds file paths that work on every operating system.
Syntax
from collections import Counter, defaultdict
from datetime import date, timedelta
from pathlib import Path Real-world scenario
Billing systems compute due dates with timedelta, and analytics scripts count events with Counter before reaching for bigger libraries.
Test yourself
5 questions. Get 4 right and this lesson is marked complete.
Pass the quiz to complete this lesson.
๐ Every lesson counts toward your certificate Next: pip and virtual environments โQuestions people ask
What does "batteries included" mean in Python?
That Python ships with a large standard library for common jobs (files, dates, JSON, maths, networking), so you can do a lot without installing anything.
What is the difference between the standard library and PyPI?
The standard library comes with Python. PyPI is the public index of extra packages, such as pandas or requests, that you install with pip.
Interview questions
How this topic comes up in Python interviews. Answer out loud first, then open the model answer.
beginner What does "batteries included" mean in Python?
That Python ships with a large standard library for common jobs (files, dates, JSON, maths, networking), so you can do a lot without installing anything.
beginner What is the difference between the standard library and PyPI?
The standard library comes with Python. PyPI is the public index of extra packages, such as pandas or requests, that you install with pip.
intermediate Do standard library modules need pip install?
No, they ship with Python. They come with Python.
intermediate Which module has Counter?
collections. collections.Counter.
Quick revision
Remember
- Count with collections.Counter
- Work with dates and timedelta
- Know where to look before reinventing
- Python's motto is "batteries included". Search docs.python.org/3/library before pip installing something.
Syntax
from collections import Counter, defaultdict
from datetime import date, timedelta
from pathlib import Path Official documentation
- The Python Standard Library (docs.python.org)