Nobody writes their own square root. Libraries are collections of ready-made procedures you import and use — and reading their documentation to figure out an unfamiliar one is itself a skill the exam tests.
Focus on import and calling something from a library. Enrolled in our
Runestone course? Open it from there so your progress counts.
Still in Programs, opening Week 4. You can write procedures; now you learn to borrow them by the thousand. A library is procedural abstraction at the largest scale — someone else’s tested code, ready to call by name.
math.sqrt(16) and move on. Reinventing it would be a waste, and probably buggier
than the version experts already perfected.
A library is a bundle of such
procedures. You import it and call what you need. The real skill isn’t
memorizing every one — it’s reading the documentation for a function
you’ve never seen and using it correctly. That’s a named skill in the CED.
A library is a collection of prewritten procedures. You bring it in with
import, then call its procedures with the library’s name in front:
import math print(math.sqrt(16)) # 4.0 import random print(random.randint(1, 6)) # a die roll
# bring in the math library # call sqrt from it — you did # not write sqrt # bring in the random library # call randint from it
Hover or tap a line to light its twin. math.sqrt means “the
sqrt procedure that lives in math.” The library name in front tells
Python where to find it.
Here’s a documentation entry for a procedure you haven’t used. Read it, then predict what the call returns — exactly what the exam asks you to do.
Five questions, including “read this doc and predict the result.” Then pick your answer.
Apps talk to maps, payments, weather, and login systems through APIs — menus of procedures other companies expose. A weather app doesn’t measure the sky; it calls a weather API. “Sign in with Google” is an API call. The reason a small team can build something powerful is that they import 95% of it.
This is abstraction and trust at global scale — and its risks scale too. When a widely-used library has a security hole, everything built on it is exposed at once (you’ll see this in Unit 7). “Reading the docs” and knowing what you’re importing isn’t busywork; it’s how professionals stay safe standing on other people’s code.
random, for dice,
coins, and simulations.