"A string is just an array of characters. The only plot twist is that, in Python, you're not allowed to edit it — and that one rule creates a famous performance trap."
Underneath, It's an Array
Everything you learned about arrays applies to strings, because a string is an array of characters. s[3] is O(1) address math. Scanning a string for a character is O(n). Slicing s[2:7] copies that range, O(k). When you treat "find the first vowel" or "reverse this word" as array problems, the techniques from this whole track carry straight over.
The One Twist: Immutability
Here's where strings diverge from lists: in Python, strings are immutable. You cannot change a character in place — s[0] = 'x' is an error. Any "modification" actually builds a brand-new string. That sounds harmless until you do it in a loop, and then it becomes the single most famous performance footgun in beginner Python.
The += Trap
Consider building a big string by repeatedly appending: result += piece inside a loop. Because strings are immutable, each += can't extend the existing string — it allocates a whole new string and copies every character so far into it. Append to a string of length k and you copy k characters. Do that n times and you've copied 1 + 2 + 3 + … + n ≈ n²/2 characters. Your innocent loop is secretly O(n²).
The fix is a one-liner reflex: collect the pieces in a list (whose append is O(1)), then fuse them once with "".join(pieces), which is a single O(n) pass. Same output, O(n) instead of O(n²). This is the array lens paying off — you already know list-append is cheap and string-rebuild is not.
Why Make Them Immutable At All?
Immutability isn't a punishment — it buys real things. Because a string never changes, it can be hashable (so it can be a dict key or set member — the entire next track depends on this). It's safe to share between parts of a program with no fear someone mutates it underneath you. And identical strings can be interned (stored once, reused). The += trap is the price; hashable, shareable, safe strings are what you bought with it.
Pippa's Confession
report += line in a loop over thousands of rows. On the test file it was instant; on the real export it crawled for a full minute. Dad took one look: "You're rebuilding the whole report every line." I switched to a list and one join at the end — a minute became milliseconds. The lesson stuck harder than any lecture: immutability is invisible until it's quadratic.