Python Lists & Mutable Sequences
A Python list is like your grocery list scribbled on paper: items have a defined order, you can add more items at the bottom with .append(), cross items off, or swap things out at will. Defined with square brackets [].
"Imagine an organized spice rack where each jar has a slot number. You can add new spices to the rack, swap paprika for garlic, or count how many spices you have in total."
Deep Dive: How It Works
Lists are ordered, mutable (changeable) sequences that can store any mix of data types (integers, strings, floats, booleans, and even nested lists).
Creating lists: Defined with square brackets: fruits = ["apple", "banana", "cherry"]. An empty list is created with [] or list().
Accessing elements: Lists are 0-indexed. fruits[0] gives "apple", fruits[1] gives "banana". Negative indices count backward from the end: fruits[-1] gives the last item ("cherry").
Common methods: .append(item) adds to the end, .insert(index, item) inserts at a specific position, .remove(item) deletes by value, and len(list) returns the total item count.
Syntax Blueprint
items = ["A", "B", "C"]
items.append("D") # Adds "D" to the end
first = items[0] # "A"
last = items[-1] # "D"Use square brackets [] for creation and indexing. Indices start at 0.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
IndexError: list index out of rangeWhy it happens: Trying to access index 3 in a 3-item list (which only has indices 0, 1, 2).
How to fix: Remember that the last index is always len(my_list) - 1 or use my_list[-1].
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Append an element to a list
Create a list colors = ["red", "blue"].
Append "green" to it and print the updated colors list.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.