Storing Many Values
A single variable holds one value; a collection holds many. The workhorse is the list (or array) — an ordered sequence of values under one name.
scores = [90, 85, 70, 100]
Each element has a position, its index. A near-universal convention is that indices start at 0: scores[0] is 90, scores[1] is 85, and the last element of a 4-item list is scores[3], not scores[4]. Reading past the end (scores[4] here) is an index-out-of-range error. The number of elements is the list's length (here 4). Lists support adding, removing, and updating elements, and iterating over them with a loop.
A different collection is the dictionary (map, or associative array), which stores key–value pairs and looks up values by key rather than by position:
ages = {"Ana": 30, "Ben": 25}
ages["Ana"] # 30
A dictionary is unordered by position but gives fast lookup by key. The rule of thumb: use a list when order and position matter and items are accessed by their place in sequence; use a dictionary when you look items up by a meaningful key (a name, an id) rather than a numeric position.
Common pitfall: forgetting that indexing starts at 0. In a list of lengthn, the valid indices are0throughn-1; the last element is at indexn-1, and accessing indexnruns off the end. This off-by-one at the boundary is one of the most common beginner errors.