Introduction
Imagine you need to keep a list of items in order, like a shopping list or a row of books on a shelf. You want a way to store and find each item quickly and easily. This is where arrays come in as a simple and effective solution.
Think of a row of mailboxes lined up side by side, each with a number. You can quickly find your mailbox by its number without checking each one. The mailboxes are fixed in place and all look similar, making it easy to organize and access mail.
┌─────────┬─────────┬─────────┬─────────┐ │ Index 0 │ Index 1 │ Index 2 │ Index 3 │ ├─────────┼─────────┼─────────┼─────────┤ │ Item0 │ Item1 │ Item2 │ Item3 │ └─────────┴─────────┴─────────┴─────────┘
numbers = [10, 20, 30, 40] print(f"First item: {numbers[0]}") print(f"Third item: {numbers[2]}")