Array Basics
Step 1 of 6
read
12
7
30
5
012345
An array stores values back to back, so slot i always sits at base + i × size.
The Idea
An array stores items back to back in memory, so the computer can compute any slot's address with simple arithmetic. Reading or writing by index is O(1). Inserting in the middle is not, because everything after it has to shift.
Real-World Example
A parking garage numbers every space. You drive straight to space 47 without passing the other 46. But squeezing a brand new space into the middle of a row means renumbering every space after it.
The Code
Your turn
Fill in the blank.
letters = ["a", "b", "c", "d"]
# print the third element
print(letters[___])Mini quiz
1 / 3