What is the difference between Python's list methods append and extend?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
append and extend both add data to a Python list, but they describe different intentions. One adds a single element, and the other concatenates elements from an iterable. If you mix them up, you can silently create nested lists, split strings into characters, or change the shape of your data pipeline.
How append and extend Actually Behave
append(x) adds one object to the end of the list. Python does not inspect x to decide whether to flatten it.
extend(iterable) iterates through its argument and appends each item one by one.
A practical memory aid is this: if you want list length to grow by exactly one, use append. If you want to merge another sequence into the list, use extend.
Input Types and Why They Matter
The most common confusion is that extend accepts any iterable, not just lists. That includes tuples, sets, generators, and strings.
The second call may surprise people. A string is an iterable of characters, so extend adds each character separately. If you wanted the whole string as one element, append("cd") is correct.
Generators also work with extend, which is useful when streaming values.
Mutation and Return Values
Both methods mutate the list in place and return None. This is important because method chaining fails silently if you expect a list back.
Because these methods mutate in place, all references to the same list see the change.
If shared mutation is risky in your code path, create a copy first by using a.copy().
Choosing Clearly in Real Code
In production code, selecting the right method is mostly about preserving data shape.
Use append when storing composite objects like records, rows, or sublists.
Use extend when flattening one level or combining two sequences.
Also note that list_a += list_b is effectively the same idea as extend for lists and mutates in place.
If your team reviews many data-transform functions, clear intent matters more than micro-optimization. A readable append or extend call is easier to maintain than clever one-liners.
Performance Notes Without Overstating
For bulk addition, one extend call is usually cleaner and often faster than a loop that repeatedly calls append.
That said, the biggest wins usually come from algorithm choices, not tiny method differences. Measure with realistic input sizes before optimizing deeply.
Common Pitfalls
- Using
appendwhen you intended concatenation, which creates unwanted nested lists. - Using
extendon a string and accidentally splitting it into characters. - Expecting either method to return a new list value.
- Mutating a list that is shared through multiple references.
- Flattening too aggressively with
extendand losing intentional structure.
Summary
appendadds one object as one element.extendconsumes an iterable and adds each item.- Strings are iterables, so
extendon text adds characters. - Both methods mutate in place and return
None. - Choose based on data shape: preserve structure with
append, merge sequences withextend.

