What is a List? The Intuition
Imagine you're organising a small party. You have a guest list — a single piece of paper where you write down names, one after another, in a specific order. You can add a new friend at the end, cross someone out, or check who is third on the list. You might even have a mix of things: names, phone numbers, maybe a note like "bring cake".
A list in programming is exactly that: a single container that holds multiple items in a definite order. It's the most natural way to group related data when the order matters and you expect the collection to change — items get added, removed, or replaced.
The key intuition: a list is an ordered, mutable collection. "Ordered" means every item has a position (first, second, third…). "Mutable" means you can change the list after creating it — add, remove, or modify items.
The Precise Statement
A list is a built-in data type in Python (and many other languages) that stores a sequence of elements. In Python, a list is written as a comma-separated sequence of values enclosed in square brackets [ ].
guests = ["Aisha", "Ben", "Carlos", "Diana"]
Each element in a list can be of any type — numbers, strings, even other lists — and different elements in the same list can have different types.
mixed = [42, "hello", 3.14, True, [1, 2, 3]]
How Lists Work: The Core Mechanics
Indexing: Finding Your Spot
Every element in a list has an index — its position number. Python uses zero-based indexing: the first element is at index 0, the second at index 1, and so on.
guests = ["Aisha", "Ben", "Carlos", "Diana"]
print(guests[0]) # Aisha
print(guests[2]) # Carlos
You can also use negative indices to count from the end: guests[-1] is the last element ("Diana"), guests[-2] is the second-last ("Carlos").
Mutability: Changing the List
Unlike strings (which are immutable), you can directly change any element of a list:
guests[1] = "Beatrice" # Replace "Ben" with "Beatrice"
You can add elements with .append() (adds to the end) or .insert() (adds at a specific position):
guests.append("Elena") # ["Aisha", "Beatrice", "Carlos", "Diana", "Elena"]
guests.insert(0, "Zara") # ["Zara", "Aisha", "Beatrice", "Carlos", "Diana", "Elena"]
Remove elements with .remove() (by value) or .pop() (by index):
guests.remove("Carlos") # Removes the first occurrence of "Carlos"
last_one = guests.pop() # Removes and returns the last element
second_one = guests.pop(1) # Removes and returns the element at index 1
Slicing: Getting a Sub-List
You can extract a portion of a list using the slice notation [start:stop:step]:
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(numbers[2:6]) # [2, 3, 4, 5] (index 2 up to, but not including, 6)
print(numbers[:4]) # [0, 1, 2, 3] (from start up to index 4)
print(numbers[5:]) # [5, 6, 7, 8, 9] (from index 5 to end)
print(numbers[::2]) # [0, 2, 4, 6, 8] (every second element)
Slicing creates a new list — it does not modify the original. This is a common source of confusion for beginners.
Why Lists Matter …