Python append() vs extend(): What Is the Difference?
append(x) adds one item to the end of a list (even if it is a list), while extend(iterable) adds each element of an iterable to the end; both change the list in place and return None.Both methods grow a list at the end, which is why they are easy to confuse. The difference shows up when you give them something that contains several values. append() treats whatever you pass as a single object and stores it as-is. extend() walks through what you pass and adds its elements one by one.
If you pick the wrong one you either get an unexpected nested list or a list of single characters. Detailed pages are available for list.append() and list.extend(), and the list methods lesson puts them in context.
a = [1, 2]
b = [1, 2]
a.append([3, 4])
b.extend([3, 4])
print(a)
print(b)append() vs extend() comparison table
| Aspect | `append(x)` | `extend(iterable)` |
|---|---|---|
| Adds | Exactly one item | Every element of the iterable |
| Argument type | Any object | Any iterable: list, tuple, set, string, range, generator |
| Length grows by | 1 | len(iterable) |
Passing [3, 4] | Adds one nested list: [1, [3, 4]] | Adds two items: [1, 3, 4] |
Passing a string "hi" | Adds "hi" | Adds "h" and "i" separately |
Passing a number 5 | Works | TypeError: an int is not iterable |
| Returns | None | None |
| Time complexity | O(1) on average | O(k) for k new items |
When to use append()
Use append() when you have one value to add.
- Building a list in a loop: one result per pass.
- Adding a record, such as a tuple or dictionary, as a single element.
- Making a nested list on purpose, for example a grid where each row is a list. See nested data.
It is the most common way to build lists, for example in a for loop.
When to use extend()
Use extend() when you want to merge many items into an existing list.
- Joining two lists without nesting:
all_items.extend(new_items). - Adding the output of a generator or
range()directly. - Collecting several batches of results into one flat list.
The += operator on a list behaves like extend() and also accepts any iterable. The expression a + b, however, makes a new list and leaves a unchanged. A list comprehension is another way to build a flat list.
Common surprise: strings and extend()
A string is an iterable of characters, so letters.extend("cat") adds "c", "a" and "t" as three items. If you meant to add the whole word as one item, use append("cat"). If you wanted to add several words, put them in a list: extend(["cat", "dog"]).
Examples you can run
Press Run, then edit the code and run it again.
Nested list vs flat list
The same data produces a different shape depending on the method.
morning = ["tea"]
evening = ["rice", "dal"]
nested = morning.copy()
nested.append(evening)
flat = morning.copy()
flat.extend(evening)
print(nested, len(nested))
print(flat, len(flat))Expected output['tea', ['rice', 'dal']] 2
['tea', 'rice', 'dal'] 3
extend() with a string splits it into characters
Strings are iterable, so each character becomes an item.
tags = []
tags.extend("abc")
print(tags)
tags.append("abc")
print(tags)Expected output['a', 'b', 'c']
['a', 'b', 'c', 'abc']
extend() accepts any iterable
A tuple, a range and a set can all be unpacked into the list. The set is sorted first for stable output.
nums = [1]
nums.extend((2, 3))
nums.extend(range(4, 6))
nums.extend(sorted({7, 6}))
print(nums)Expected output[1, 2, 3, 4, 5, 6, 7]
Common mistakes
Using append() when you wanted to merge lists
✗ Wrong
cart = ["pen"]
cart.append(["book", "ruler"])
print(len(cart))✓ Right
cart = ["pen"]
cart.extend(["book", "ruler"])
print(len(cart))Use extend() to add the elements individually.
Calling extend() with a single number
✗ Wrong
scores = [70, 80]
scores.extend(90)✓ Right
scores = [70, 80]
scores.append(90)
print(scores)Use append(90) for one item, or wrap it in a list: extend([90]).
Assigning the result
✗ Wrong
a = [1]
a = a.extend([2, 3])
print(a)✓ Right
a = [1]
a.extend([2, 3])
print(a)Both methods return None and change the list in place, so do not assign their result.
Python append() vs extend(): What Is the Difference?: questions people ask
What is the difference between append and extend in Python?
append() adds its argument as a single element, while extend() adds every element of an iterable. [1].append([2, 3]) gives [1, [2, 3]], but [1].extend([2, 3]) gives [1, 2, 3].
Is extend() the same as +=?
For a list, a += b modifies a in place just like a.extend(b). By contrast, a = a + b builds a new list.
Which is faster, append or extend?
For one item append() is faster. For many items, a single extend() call is faster than a loop of append() calls because the work happens inside Python's optimised code.
Keep learning
Step-by-step lessons:
Python ListsPython List MethodsPython List Comprehensions
Related:
Python List append() MethodPython List extend() MethodPython List vs Tuple: Differences and When to Use EachPython sort() vs sorted(): What Is the Difference?
More in functions and methods:
Python sort() vs sorted(): What Is the Difference?Python remove() vs pop() vs del: What Is the Difference?Python print() vs return: What Is the Difference?Python str() vs repr(): What Is the Difference?Python Deep Copy vs Shallow Copy: What Is the Difference? See all →