Add List Items
Adding items to a list is one of the most common operations in Python.
Because lists are mutable, you can insert new elements at any position—beginning, middle, or end.
This topic covers all valid ways to add items to a list, with clear examples and edge cases.
Add Items Using append()
The
append() method adds one item to the end of the list.python
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)
python
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)
Add Items Using insert()
The
insert() method adds an item at a specific index.Syntax
python
list.insert(index, value)
python
fruits = ["apple", "cherry"]
fruits.insert(1, "banana")
print(fruits)
python
numbers = [1, 2, 4]
numbers.insert(2, 3)
print(numbers)
Add Multiple Items Using extend()
The
extend() method adds multiple items from another iterable.python
numbers = [1, 2, 3]
numbers.extend([4, 5, 6])
print(numbers)
python
fruits = ["apple"]
fruits.extend(("banana", "cherry"))
print(fruits)
Add List to Another List (Important Difference)
Using append()
python
a = [1, 2]
b = [3, 4]
a.append(b)
print(a)
Result is a nested list.
Using extend()
python
a = [1, 2]
b = [3, 4]
a.extend(b)
print(a)
Result is a single flat list.
Add Items Using List Concatenation (+)
python
list1 = [1, 2]
list2 = [3, 4]
result = list1 + list2
print(result)
Original lists remain unchanged.
Add Items Using Slice Assignment
python
numbers = [1, 2, 5]
numbers[2:2] = [3, 4]
print(numbers)
python
numbers[:0] = [0]
print(numbers)
Add Items in a Loop
python
numbers = []
for i in range(5):
numbers.append(i)
print(numbers)
python
items = []
for value in [10, 20, 30]:
items.insert(0, value)
print(items)
Add Items Conditionally
python
numbers = [10, 20, 30]
if 40 not in numbers:
numbers.append(40)
print(numbers)
Add Nested Items
python
matrix = [[1, 2], [3, 4]]
matrix.append([5, 6])
print(matrix)
python
matrix[0].append(10)
print(matrix)
Common Mistakes
Expecting append() to Add Multiple Items
python
numbers = [1, 2]
numbers.append([3, 4])
print(numbers)
This adds a list inside a list.
Using Wrong Index in insert()
python
numbers = [1, 2, 3]
numbers.insert(100, 4)
print(numbers)
Python inserts at the end, not an error.
Performance Tip
append()is fast and preferredinsert()at the beginning is slower for large listsextend()is best for adding many items
Summary
append()adds one item at the endinsert()adds item at a specific indexextend()adds multiple items+creates a new list- Slice assignment allows flexible insertion
- Lists can be nested
- Choose method based on use case
This topic naturally leads to:
- Remove List Items
- List Copying
- List Comprehensions
- List Performance Tips