fruits = ["apple", "banana"]
fruits[0] = "mango" # change an item
fruits.append("cherry") # add to the end
fruits.insert(1, "kiwi") # insert at position 1
print(fruits)
# ['mango', 'kiwi', 'banana', 'cherry']
🗑️ Removing items
fruits = ["apple", "banana", "cherry"]
fruits.remove("banana") # remove by value
last = fruits.pop() # remove & return the last item
print(fruits) # ['apple']
print(last) # cherry
🔁 Looping through a list
This is where lists shine — a for loop visits every item:
scores = [90, 85, 100]
for s in scores:
print(f"Score: {s}")
🛠️ Handy list tools
nums = [3, 1, 4, 1, 5]
print(len(nums)) # 5 how many items
print(sum(nums)) # 14 add them all
print(max(nums)) # 5 biggest
print(min(nums)) # 1 smallest
nums.sort() # put in order
print(nums) # [1, 1, 3, 4, 5]
print("apple" in fruits) # True/False — is it there?
✅ What you learned
Lists hold ordered collections in [ ].
Read items by index (starting at 0); [-1] is the last.
Add with .append() / .insert(), remove with .remove() / .pop().
Loop with for; use len, sum, max, min, sort, and in.
🎮 Time to Practice!
Collect, change, and explore lists of stuff. 📦
🌈
Task 1: Print Each Color
Easy
A list colors holds "red", "green", "blue". Use a for loop to print each color on its own line.
colors = ["red", "green", "blue"]
for c in colors:
print(c)
🛒
Task 2: Shopping List
Medium
Start with cart = ["milk", "eggs"]. Add "bread" to the end, then print the whole list. Expected: ['milk', 'eggs', 'bread']