A Python list stores an ordered collection of items that you can read, change, add to, and remove from. Use square brackets to create one: colors = ["red", "blue"]. List positions start at index 0, so colors[0] is "red".
What is a Python list?
A list is a mutable sequence: it keeps items in order, and you can change its contents after creating it. Lists support indexing and slicing, as well as iteration. The Python 3.14.7 data structures tutorial explains these sequence operations alongside related sequence types.
As an Amazon Associate I earn from qualifying purchases.
colors = ["red", "blue", "green"]
print(colors[1]) # blue
print(colors[0:2]) # ['red', 'blue']
colors[1] = "yellow"
print(colors) # ['red', 'yellow', 'green']
Use a for loop to process each item in order:
for color in colors:
print(color)
How do you add items to a list?
append() adds one item to the end. extend() adds each item from an iterable. The distinction matters when the item you want to add is itself a list.
numbers = [1, 2]
numbers.append([3, 4])
print(numbers) # [1, 2, [3, 4]]
numbers = [1, 2]
numbers.extend([3, 4])
print(numbers) # [1, 2, 3, 4]
To add an item before a particular position, use insert(index, item):
#1 Best Overall
colors = ["red", "blue"]
colors.insert(1, "yellow")
print(colors) # ['red', 'yellow', 'blue']
How do you remove items?
Choose the removal operation based on whether you have a value, a position, or a range—and whether you need the removed item back.
| Operation | How it selects items | What it does |
|---|---|---|
remove(value) |
First item equal to the value | Removes it; raises ValueError if no matching item exists |
pop([index]) |
Item at the given index, or the last item if the index is omitted | Removes and returns the item |
del list[index] or del list[start:stop] |
Index or slice | Deletes the selected item or items without returning them |
items = ["pen", "book", "pen"]
items.remove("pen")
print(items) # ['book', 'pen']
last_item = items.pop()
print(last_item) # pen
print(items) # ['book']
del items[0]
remove() removes only the first equal value. To remove every matching value, build a new list containing only the items you want to keep; a comprehension is shown below.
Rank #2
Which list operations change the list?
Methods such as append(), insert(), remove(), reverse(), and sort() modify the existing list. Modifying list methods return None, not the changed list, so do not assign their result back to the list variable.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsscores = [7, 2, 9]
scores.sort()
print(scores) # [2, 7, 9]
scores = [7, 2, 9]
result = scores.sort()
print(result) # None
Use sorted() when you want a sorted result while keeping the original list unchanged:
scores = [7, 2, 9]
ordered = sorted(scores)
print(ordered) # [2, 7, 9]
print(scores) # [7, 2, 9]
copy() also returns a result: a shallow copy of the list. It creates a separate outer list, but nested mutable objects are not recursively copied.
Can a list work as a stack or queue?
Stack: add and remove at the end
A list is a natural fit for a stack, where the most recently added item is removed first. Use append() to put an item on top and pop() to take the last item off.
stack = ["first"]
stack.append("second")
top = stack.pop()
print(top) # second
print(stack) # ['first']
Queue: use a deque for both ends
A list can hold queue items, but removing from its front requires the remaining elements to shift. For a queue that adds and removes at both ends, use collections.deque, which is designed for fast operations at either end.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →from collections import deque
queue = deque(["first", "second"])
queue.append("third")
next_item = queue.popleft()
print(next_item) # first
print(queue) # deque(['second', 'third'])
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.How do list comprehensions work?
A list comprehension constructs a new list by transforming each input item and, optionally, selecting items with a condition. Start with a regular loop:
Best Value
squares = []
for number in range(5):
squares.append(number * number)
The equivalent comprehension is shorter and still creates a new list:
squares = [number * number for number in range(5)]
Add a condition to include only selected items:
even_squares = [number * number for number in range(5) if number % 2 == 0]
print(even_squares) # [0, 4, 16]
The Python tutorial’s list-comprehension section covers this construction form and further examples.
Quick reference: common list methods
append(item): add one item at the end.extend(iterable): add the iterable’s items at the end.insert(index, item): insert before the specified position.remove(value): remove the first equal value.pop([index]): remove and return an indexed item, or the last item by default.sort(): sort the existing list in place.reverse(): reverse the existing list in place.copy(): return a shallow copy.
For the full behavior and additional list operations, see the Python 3.14.7 data structures tutorial.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




