
Lists are ordered, mutable sequences. Can hold mixed types.
fruits = ["apple", "banana", "cherry"] numbers = [1, 2, 3, 4, 5] mixed = [1, "hello", True, 3.14]
Accessing elements:
fruits[0] # "apple" fruits[-1] # "cherry" fruits[1:3] # ["banana", "cherry"]
Modifying lists:
fruits.append("date") # add to end
fruits.insert(1, "avocado") # insert at index
fruits.remove("banana") # remove by value
fruits.pop() # remove last
fruits.pop(0) # remove by index
fruits.sort() # sort in place
len(fruits) # lengthList comprehension (Pythonic):
squares = [x**2 for x in range(10)] evens = [x for x in range(20) if x % 2 == 0]
Common trap: list2 = list1 does NOT copy — both point to the same list. Use list2 = list1.copy() or list2 = list1[:].
Reference:
TaskLoco™ — The Sticky Note GOAT