Python append vs extend: Differences and Use Cases
Python append vs extend: Understand how the list append() and extend() methods differ, when to use each, and how they affect performance and memory.

In Python, list.append() and list.extend() are two methods that both add elements to a list, but they behave in fundamentally different ways. The choice between append and extend affects how the list grows, how arguments are processed, and how the code reads. Understanding the distinction is essential for writing correct and efficient Python code.
What append and extend Do
append() adds a single object to the end of a list. The object is inserted as-is, regardless of its type. extend() iterates over the provided argument and adds each element from that iterable to the list individually.
numbers = [1, 2, 3]
numbers.append([4, 5])
print(numbers) # [1, 2, 3, [4, 5]]
letters = ['a', 'b']
letters.extend(['c', 'd'])
print(letters) # ['a', 'b', 'c', 'd']The first example places the entire list [4, 5] as a single element at the end. The second example unpacks the iterable and appends each item separately. This is the core behavioral difference.
In-Place Operation and Return Value
Both methods modify the list in place and return None. They do not create a new list. This is a common source of bugs when developers expect a return value and assign it to a variable.
result = [1, 2].append(3)
print(result) # NoneBecause the operation is in-place, the original list is updated. If you need a new list, you must copy the original first or use concatenation (+), which returns a new list. The in-place nature also means both methods are efficient when you want to avoid allocating a second list.
Argument Handling: Single Element vs Iterable
append() takes exactly one argument and adds it as a single element. extend() takes an iterable and adds each of its elements. This distinction becomes critical when working with strings, tuples, or other iterables.
word = 'cat'
list_with_string = []
list_with_string.append(word)
print(list_with_string) # ['cat']
list_with_chars = []
list_with_chars.extend(word)
print(list_with_chars) # ['c', 'a', 't']append('cat') stores the whole string as one element. extend('cat') treats the string as a sequence of characters and adds each character. If you intend to add a string as a single item, use append. If you want to split it into characters, use extend.
Practical Examples and Common Mistakes
A frequent mistake is using append when extend is needed, or vice versa. Consider building a list from multiple iterables:
# Wrong: appends the whole list as one element
all_items = []
for part in [[1, 2], [3, 4]]:
all_items.append(part)
print(all_items) # [[1, 2], [3, 4]]
# Correct: extends with each element
all_items = []
for part in [[1, 2], [3, 4]]:
all_items.extend(part)
print(all_items) # [1, 2, 3, 4]Another common issue arises when using extend with a generator. extend consumes the generator immediately, so you cannot reuse it later. If you need to reuse the data, convert it to a list first.
Performance and Memory Considerations
Appending one element with append is amortized O(1). Extending with an iterable of length k is amortized O(k), because extend adds k elements. The performance difference is proportional to the number of elements added, not to the method itself.
extend can be more efficient than calling append in a loop because it avoids the Python-level loop overhead. For example:
# Loop with append
new_list = []
for item in iterable:
new_list.append(item)
# Single extend
new_list = []
new_list.extend(iterable)The extend version can be faster when it replaces an explicit loop, because it avoids repeated Python-level append calls. The target list may still resize while elements are added, but Python's allocation strategy overallocates capacity, so the resizing cost is amortized.
Memory usage also differs. append adds a reference to the existing object; it does not copy the object. extend adds references to each element from the iterable. Neither method performs a deep copy. If the iterable holds mutable objects, both the original and the list share the same object references.
When to Use append vs extend
Use append when you need to add a single item, regardless of whether that item is a number, string, list, or dictionary. Use extend when you have an iterable and want to merge its elements into the list.
| Method | Argument | Result | Typical Use Case |
|---|---|---|---|
append | One object | Adds the object as a single element | Adding a value to a list, e.g., collecting results |
extend | One iterable | Adds each element from the iterable | Merging lists, flattening one level, adding generator output |
A concrete decision rule: if you write list.append(x) and x is a list, you get a nested list. If you write list.extend(x) and x is a list, you get a flat list. Choose based on the desired structure.
Advanced Usage: Nested Lists and Generators
extend works with any iterable, including generators, sets, and custom iterable objects. This makes it useful for building lists from data streams without intermediate lists.
def squares(n):
for i in range(n):
yield i * i
result = []
result.extend(squares(4))
print(result) # [0, 1, 4, 9]append is often used to build lists of lists, such as when grouping data:
groups = []
for group in data:
groups.append(group) # group is itself a listBe careful with extend on strings: it splits the string into characters. If you want to add a string as a single element, use append. If you want to add multiple strings as separate elements, use extend with a list of strings:
words = ['hello', 'world']
list_of_words = []
list_of_words.extend(words)
print(list_of_words) # ['hello', 'world']Compatibility and Edge Cases
Both methods are available in all supported Python versions (3.x). They behave consistently across CPython, PyPy, and other implementations, though performance characteristics may vary slightly.
One edge case: extend with a dictionary iterates over its keys, not its key-value pairs. If you need to add dictionary items as tuples, pass dict.items() explicitly.
d = {'a': 1, 'b': 2}
list_of_keys = []
list_of_keys.extend(d)
print(list_of_keys) # ['a', 'b']
list_of_pairs = []
list_of_pairs.extend(d.items())
print(list_of_pairs) # [('a', 1), ('b', 2)]Another edge case is using extend with a tuple or a range. Both are iterables, so the elements are added individually. append with a tuple adds the tuple as a single element.
Choosing the Right Method for Maintainable Code
Beyond correctness, the choice between append and extend affects code readability. append clearly signals that one item is being added. extend signals that an iterable's contents are being merged. Using the wrong method can confuse readers and introduce subtle bugs.
When refactoring, prefer extend over a loop of append calls when you have an existing iterable. This reduces boilerplate and makes the intention explicit. However, if the iterable is generated lazily and you need to process each element before adding it, a loop with append may be clearer.
# Clearer with append when processing each item
processed = []
for item in raw_data:
processed.append(transform(item))
# Clearer with extend when merging already transformed iterables
processed = []
processed.extend(transform_all(raw_data))In summary, append and extend serve distinct purposes. append adds a single object to a list; extend adds each element of an iterable. Understanding this difference prevents common mistakes and helps you write more efficient, readable Python code.
Try matching browser tools
All toolsSmall utilities that fit Python work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Python guides
All Python guidesPython iter(): How the Built-in Function Works
Explains Python's iter() built-in: how it creates iterators, the two-argument sentinel form, custom iterator classes, and common edge cases.
Python Pika: Queues, Exchanges, Routing Keys, and Acknowledgements
Learn how to use Python's Pika client with RabbitMQ: declare queues and exchanges, publish with routing keys, consume messages, and handle acknowledgements reliably.
Python Kafka: kafka-python vs Confluent Client
python kafka python vs confluent kafka: Compare kafka-python and Confluent Kafka Python clients: API differences, performance, feature coverage, and when to choose eac...
Python Kafka Offsets, Partitions, and Manual Commits
Learn how Kafka offsets and partitions work and how to manually commit offsets in Python consumers with kafka-python and confluent-kafka. Covers sync vs async commits, rebalances, and seeking.
More in Python
All Python guidesThe guides filed next to this one in Python, in library order.