What Is a List?
"A list is an ordered collection of items. Instead of juggling separate variables for related data, pack them into a numbered row of slots."
The Problem Lists Solve
# Without lists - messy and unscalable
fruit1 = "apple"
fruit2 = "banana"
fruit3 = "orange"
fruit4 = "grape"
# What if we have 100 fruits?
# With lists - organized and scalable
fruits = ["apple", "banana", "orange", "grape"]
List Structure: Position Matters
fruits = ["apple", "banana", "orange"]
Important: Lists start at index 0, not 1!
The final index is always len(list) - 1 (or shorthand list[-1]).
Critical Concept: Lists are ordered—position matters. Each item sits in a numbered slot called an index starting at 0.
Interactive List Builder & Index Lookup Tester
Quick Index Lookup Tester (click any button or slot below):
CHEAT SHEET
Common List Operations (append, insert, pop, len)
+ Explore
# Creating a list
fruits = ["apple", "banana"]
# Accessing items (positive & negative index)
first = fruits[0] # "apple"
last = fruits[-1] # "banana" (always grabs the final item!)
# Adding items
fruits.append("orange") # Add to end
fruits.insert(1, "grape") # Insert at index 1
# Removing items
fruits.remove("apple") # Remove by value
item = fruits.pop() # Remove and return last item
# Getting length & checking membership
count = len(fruits) # How many items?
has_apple = "apple" in fruits # True or False
CODE EXAMPLES
Two Ways to Loop Through a List
+ Explore
fruits = ["apple", "banana", "orange"]
# Method 1: Direct iteration (cleanest when you just need each value)
for fruit in fruits:
print(fruit)
# Method 2: Using range(len(...)) when you also need the index number
for i in range(len(fruits)):
print(i, fruits[i])
Twilight Tulip Collected! (12 / 16)
Lists let you group related data together and process them systematically. Next up: packaging your logic into reusable Functions!