Explain what a library and API provide to a programmer
Describe the benefits of using existing libraries
Identify which program parts might come from a library vs custom code
Use an AP pseudocode procedure from a provided API description
📈
Exam Impact: Library and API concepts are conceptual MCQ targets. The Create Task may reference libraries the student uses.
💡 Why This Matters
When a weather app shows your forecast, it didn't build the satellite data collection system. Libraries let programmers build on what others have already solved.
What Is a Library?
A library is a collection of pre-written procedures. An API (Application Programming Interface) describes what procedures are available and how to call them -- not how they work internally. Using a library is a form of abstraction.
import random
import math
n = random.randint(1, 100)
s = math.sqrt(144) # 12.0
r = math.ceil(3.2) # 4
{AP pseudocode uses a provided API.}
{The AP reference sheet provides:}
RANDOM(low, high)
{Returns a random integer}
{between low and high inclusive.}
Benefits of Libraries
Speed: Don't rewrite what already exists
Correctness: Library code is tested and trusted
Abstraction: Use the result without knowing the algorithm
Collaboration: Different teams can use the same library independently
Practice Problems
🔎 Practice MCQ
What does an API provide to a programmer?
🔎 Practice MCQ
A student uses a library's drawCircle(x,y,radius) procedure. Which is a direct benefit?
🔎 Practice MCQ
Which statement about libraries is NOT accurate?
⚠️ Predict your answer BEFORE clicking.
🎮 Game
Library Concept Quiz
Test your understanding of libraries and APIs. 8 questions.
0
Correct
1/8
Question
0
Streak 🔥
🤔 Evaluate:
0/8
correct
💻 Python Code Editor
Practice Problems
Write Python and check your answer. Paste into Replit for complex programs.
Problem 1 of 3
Use import random and print a random integer 1-10. (Any 1-10 value accepted.)
Hint: print(random.randint(1, 10)) -- randint includes both endpoints.
Problem 2 of 3
Use import math and print the square root of 169. Expected: 13.0
Hint: print(math.sqrt(169))
Problem 3 of 3
Spot the bug: should print ceiling of 4.1 (=5) but crashes. print(math.ceil(4.1))
Hint: math.ceil(4.1)=5. Make sure 'import math' is at the top.
Frequently Asked Questions
A library is the actual collection of code. An API is the description of how to use it -- names, parameters, and return values. You interact with a library through its API.
Yes. Acknowledge any code written by someone else. Using library code without acknowledgment can affect your score.
Yes. A graphics library might use a math library internally. The programmer using the graphics library doesn't need to know that detail.
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed.
Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Typically responds within 24 hours
✓
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.