Data Structures18 min read
List Fundamentals
Learn lists like a teacher would: what they are, when to use them, how indexing works, and how to avoid beginner mistakes with examples and visuals.
David Miller
December 24, 2025
2.0k90
A list stores multiple items in an ordered sequence.
When to use a list
Use a list when:
- you care about order (first, second, third)
- you need duplicates
- you add/remove items often
Creating lists
numbers = [10, 20, 30]
names = ["Tom", "Sarah", "Mike"]
mixed = ["Tom", 25, True]
Indexing (most important)
Index starts from 0.
names = ["Tom", "Sarah", "Mike"]
print(names[0]) # Tom
print(names[1]) # Sarah
Negative indexing
print(names[-1]) # Mike (last item)
Slicing (get a part)
nums = [1, 2, 3, 4, 5]
print(nums[1:4]) # [2, 3, 4]
Add and remove
fruits = ["apple", "banana"]
fruits.append("orange") # add at end
fruits.insert(1, "grape") # add at position
print(fruits)
fruits.remove("banana") # remove by value
last = fruits.pop() # remove last and return it
print(last)
Beginner mistakes
- IndexError: accessing out of range
# names[10] # error
- Confusing copy with reference
a = [1, 2]
b = a
b.append(3)
print(a) # [1,2,3] because both point to same list
Fix:
a = [1, 2]
b = a.copy()
b.append(3)
print(a) # [1,2]
Graph: list mental model
flowchart LR
A[List] --> B[Index 0]
A --> C[Index 1]
A --> D[Index 2]
Remember
- List is ordered and mutable
- Index starts at 0
- Use copy() when you want a real copy
#Python#Beginner#List