You Have Already Used Libraries
Learning Objectives
- You can explain what a library gives to a program.
- You can distinguish built-in functions, modules, packages, libraries, and APIs at a beginner level.
- You can identify standard-library modules you have already used.
- You can explain why using a library still requires understanding the data and the problem.
The word library can sound like a new category of programming, but you have already been using library code. When you wrote CSV files, you used csv. When the study log started recording dates, you used datetime. When the project moved toward structured data in Structuring Your Data, it used json.
Those tools are not part of the tiny core syntax of Python. They are code that comes with Python and can be imported when needed. They save you from writing low-level details yourself:
import csv
with open("sessions.csv", encoding="utf-8") as f: reader = csv.reader(f) for row in reader: print(row)The for loop is Python syntax. The open function is a built-in. The csv.reader function comes from the csv module. A real program is usually a mixture of these layers.
Your starting point with libraries
0 / 10 points
In a short explanation (about 3-5 sentences), describe one Python library or module you have already used in this course or elsewhere.
Explain what problem it helped solve and what you still had to understand yourself.
Code from a module
0 / 5 points
In this code, which name comes from the imported module?
import csv
reader = csv.reader(f)Built-ins, Modules, Packages, Libraries
The vocabulary is a little fuzzy in everyday conversation, so use these definitions as working definitions rather than legal contracts.
A built-in is available without importing anything:
print(len(["math", "history"]))A module is one Python file or module-like unit that you import by name:
import math
print(math.sqrt(49))A package is a collection of modules arranged together. Third-party tools such as pandas and NumPy are packages in this sense, even though people often call them libraries.
A library is the broader idea: reusable code intended to be used by other programs. The Python standard library is the collection of modules and packages that come with Python. Third-party libraries are installed separately.
An API is the surface a library gives you to use it: the names you call, the arguments they expect, the values they return, and the behavior they promise.
Module or built-in
0 / 5 points
Which example uses a built-in function rather than a name from an imported module?
Standard Library and Third-Party Libraries
Python comes with a large standard library. You install Python, and modules such as csv, json, math, random, and datetime are already available. You do not install them separately.
Third-party libraries are written and distributed separately from Python itself. They are installed into your local Python environment. In this part, the important third-party libraries are:
- NumPy, which is built around arrays of numbers and operations over whole arrays.
- pandas, which is built around table-shaped data.
The study log is a good reason to learn pandas. You already know how to compute totals, averages, per-subject summaries, date windows, and rankings with loops. Pandas gives you a table abstraction that expresses many of those operations more directly.
Standard or third-party
0 / 5 points
Which statement is correct?
Libraries Do Not Replace Understanding
Libraries make powerful operations short. That is useful, but it can also hide decisions.
For example, this pandas expression will eventually make sense. You do not need to know the syntax yet; for now, read it as a preview of the kind of summary pandas can express:
df.groupby("subject")["minutes"].sum()It means “group the rows by subject, take the minutes column in each group, and sum the minutes.” Summarizing Data with pandas will teach the groupby syntax carefully. The line is short because pandas already knows how to group rows and sum columns. But the programming idea is not new. In Summarizing Your Data, you wrote the same kind of summary yourself with loops.
That previous work matters. If the result looks wrong, you need to know what the result should mean. Did the grouping use the right column? Are minutes numbers or text? Are subjects consistently lowercase? Are future-dated sessions still present? Libraries give you better tools, not better judgment by default.
What the Library Does Not Decide
A library does not know what your program means by “recent”, “long”, “valid”, or “best”. Those are still design choices.
For example, pandas can group sessions by subject. It cannot decide whether "Math" and "math" should be treated as the same subject. It can calculate an average. It cannot decide whether an empty average should be printed as 0, None, or "No sessions yet." It can sort rows by minutes. It cannot decide whether ties should keep their original order or be broken by date.
That is why the course has spent so much time on edge cases and specifications. Here is the same pandas preview again. The library call is only one line inside a larger decision:
totals = df.groupby("subject")["minutes"].sum()This line assumes that the pandas table, called a DataFrame later in this part, has the shape the code expects:
- the table has a column named
subject, - the table has a column named
minutes, - the minutes values are numbers,
- and the subject names are already normalized enough for grouping.
If any of those assumptions is false, the line may fail, or worse, it may produce a plausible but misleading result. Library use is therefore also assumption management.
A Library-Use Loop
When you meet a new library feature, use a small loop:
- Import the library or name.
- Try the smallest possible example.
- Print or inspect the result.
- Change one thing and run again.
- Only then fit it into your real program.
For example:
from datetime import date
day = date.fromisoformat("2026-05-10")print(day)print(type(day))This is deliberately tiny. It answers two questions: what value comes back, and what type is it? Those two questions are enough to prevent many library-use bugs.
Small library-use loop
0 / 5 points
Arrange the steps into a useful loop for trying a new library feature.
Explain a tiny API example
0 / 10 points
Study this code:
from datetime import date
session_day = date.fromisoformat("2026-05-10")print(session_day.year)In a short explanation (about 3-5 sentences), explain what names come from the library, what value is created, and why this is a useful tiny experiment before changing a larger project.
Check Your Understanding
- What is the difference between Python syntax and a function from a module?
- Why is
csvavailable without installing anything, but pandas is not? - What does the API of a library include?
- Why is it useful to know the loop-based version of a pandas summary before using the pandas version?
AI Study Aid
Create a chapter diagram
We're looking into to what extent AI-generated diagrams could help with studying.
Use this study aid to generate an AI-generated visual summary of the material you just studied.
Each diagram style emphasizes the content in a different way, so you can choose the focus
that feels most useful.
Using the diagram generator is voluntary and does not affect your course progress. We encourage
you to try it out and see if it helps, but it's totally up to you! Your answers help us understand
how to make better study aids in the future.