AP CSP Topic 3.4 Guided Notes - Strings
Big Idea 3: Algorithms and Programming · Topic 3.4 · Guided Notes (Student)
Strings — Guided Notes
Fill these in during class or catch up here if you were absent. Print this page or work on paper — then check yourself with the CFUs on the Topic 3.4 page.
Print these notesAll CSP topics
Today’s objectives
- Evaluate string concatenation expressions, joining two or more strings end-to-end to build one new string (LO AAP-2.D)
- Identify and evaluate substrings — the pieces taken from an existing string — and read character positions without off-by-one errors (LO AAP-2.D)
Bell ringer
On scratch paper, build your 'coding-club handle' by following these steps EXACTLY, in order: (1) write the first 3 letters of your first name; (2) directly after them, with no space, write the last 2 letters of your last name; (3) directly after that, with no space, write your favorite one-digit number.
Write 2–4 sentences: Which steps JOINED pieces together, and which step pulled out just PART of a longer word? Your name normally has a space in it — where did the spaces go in your handle, and why?
01. Concatenation
Key Vocabulary (LO AAP-2.D)
| Term | Definition (write it) |
|---|---|
| String | |
| Character | |
| Concatenation | |
| Substring | |
| Position (index) |
Concatenation Joins Strings End-to-End
- If you concatenate "code" and "NOW" with nothing between them, the result is .
- To make joined strings read as separate words, you must .
- "AP" + "CSP" and "CSP" + "AP" give different results because concatenation .
The Space Only Appears If You Add It
first + last runs the names together; first + " " + last inserts the space you supplied.
AP Pseudocode (what the exam tests)
first ← "Ada" last ← "Lovelace" DISPLAY(first + last) DISPLAY(first + " " + last)
Python (the runnable version)
first = "Ada" last = "Lovelace" print(first + last) print(first + " " + last)
Output
AdaLovelace Ada Lovelace
Run and edit this yourself in the coding exercises for this topic.
Evaluate Each Concatenation
Give the exact string each expression produces. Watch for spaces that are — and are not — supplied.
Complete the empty cells.
| Expression | Result | Why |
|---|---|---|
| "cat" + "dog" | joined end-to-end; no space is added for you | |
| "cat" + " " + "dog" | the middle " " supplies the only space | |
| "AP" + "CSP" | APCSP | left piece first, then the right piece |
| "CSP" + "AP" | CSPAP | swapping the operands swaps the halves |
| "7" + "3" | these are text characters, so they join — they are NOT added to make 10 |
Watch out — “Joining Strings Adds a Space Between Them”
Myth: When you concatenate two strings, the computer automatically puts a space (or other separator) between them.
Explain why this is wrong:
Stop and think
- Evaluate by hand: DISPLAY("low" + "key"). Write the exact string, then explain in one sentence why there is no space in it.
- You want the output My rank is 4 from the text piece "My rank is" and the value 4. Write the concatenation expression, being explicit about the space and about writing the 4 as a text character.
- A classmate writes "CSP" + "AP" and expects "AP CSP". Give the actual result and name the two separate things they got wrong.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.4 page.
02. Substrings
A Substring Is Part of an Existing String
- A substring is best described as .
- Taking a substring leaves the original string .
- On the exam the 3rd character is position 3, but in Python that same character is at .
Take a Piece, Leave the Original
The exam describes a substring in words (there is no SUBSTRING procedure on the reference sheet); Python takes the piece with a slice, counting from 0.
AP Pseudocode (what the exam tests)
word ← "computer" part ← first 4 characters of word DISPLAY(part) DISPLAY(word)
Python (the runnable version)
word = "computer" part = word[0:4] print(part) print(word)
Output
comp computer
Run and edit this yourself in the coding exercises for this topic.
Read the Substring by Position
Using exam positions (counting from 1), give the substring each description names. The last column shows the matching Python index.
Complete the empty cells.
| Word | Take... | Substring | Python index note |
|---|---|---|---|
| rainbow | the first 3 characters | positions 1–3 = indexes 0–2 | |
| rainbow | the 4th character | position 4 = index 3 | |
| rainbow | the last 3 characters | bow | positions 5–7 = indexes 4–6 |
| science | the 3rd character | position 3 = index 2 |
Watch out — “The 3rd Character Is at Index 3”
Myth: To get the 3rd character of a string in Python or JavaScript, you use index 3.
Explain why this is wrong:
Stop and think
- For word = "function", write the substring that is (a) the first 3 characters and (b) the 5th character. State the exam position for each.
- In Python, "function"[3] returns 'c', not the 3rd character. Explain the off-by-one cause and give the index that returns the 3rd character.
- In one sentence, explain how a substring differs from concatenation — what each one does to the strings involved.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.4 page.
Common AP Traps
Three ways Topic 3.4 loses points on the exam — one minute now, real points in May.
Concatenation adds no spaces — in your own words:
Order matters, and the originals survive — in your own words:
Position base: exam counts from 1, code from 0 — in your own words:
Strings, in One Slide
- String concatenation joins two or more strings end-to-end to make one new string, and it adds no spaces of its own.
- Concatenation preserves operand order and leaves the original strings unchanged — "AP" + "CSP" ≠ "CSP" + "AP".
- A substring is part of an existing string — one or more of its characters — and taking it does not change the source.
- Character positions differ by base: the exam reference sheet counts from 1, while Python and JavaScript count from 0.
Exit check — I can…
- ☐ evaluate a string concatenation and give the exact result, adding spaces only where I concatenate them (LO AAP-2.D)
- ☐ explain that concatenation preserves order and produces a new string without changing the originals (LO AAP-2.D)
- ☐ identify a substring as a piece of an existing string and read it by position (LO AAP-2.D)
- ☐ convert between exam positions (from 1) and code indexes (from 0) to avoid off-by-one errors (LO AAP-2.D)
Get in Touch
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]