Question
Python List append() vs extend(): What’s the Difference?
Question
In Python, what is the difference between the list methods append() and extend()?
For example, how does each method affect a list when adding a single value versus adding multiple values from another iterable?
Short Answer
By the end of this page, you will understand how append() and extend() work in Python lists, when to use each one, and how they change the structure of a list differently. You will also see common mistakes, practical examples, and a small project to help reinforce the concept.
Concept
Python lists provide several methods for adding data, and two of the most commonly confused ones are append() and extend().
append(x)adds one item to the end of a list.extend(iterable)adds each item from an iterable to the end of a list.
This difference matters because it changes the final shape of your list.
append()
When you use append(), Python takes the object you give it and places that object at the end of the list as a single element.
numbers = [1, 2, 3]
numbers.append([4, 5])
print(numbers)
Output:
[1, 2, 3, [4, 5]]
The list [4, 5] is added as one item inside the original list.
extend()
When you use , Python loops over the iterable you provide and adds each element one by one.
Mental Model
Think of a list like a shopping bag.
append()is like putting one object into the bag, even if that object is another smaller bag.extend()is like opening a smaller bag and pouring all its contents into the main bag.
Example:
append(["apple", "banana"])puts the whole fruit bag into your shopping bag.extend(["apple", "banana"])takes out each fruit and adds them separately.
So the key question is:
Do you want to add one item, or do you want to add all the items inside something iterable?
Syntax and Examples
Core syntax
my_list.append(item)
my_list.extend(iterable)
Example 1: Add a single value with append()
fruits = ["apple", "banana"]
fruits.append("orange")
print(fruits)
Output:
['apple', 'banana', 'orange']
This is the normal use of append(): adding one new element.
Example 2: Add multiple values with extend()
fruits = ["apple", "banana"]
fruits.extend(["orange", "grape"])
print(fruits)
Output:
['apple', 'banana', 'orange', 'grape']
This adds each new fruit separately.
Example 3: with a list
Step by Step Execution
Consider this example:
items = [1, 2]
items.append([3, 4])
print(items)
items = [1, 2]
items.extend([3, 4])
print(items)
First part: append()
items = [1, 2]
- A list is created with two elements:
1and2.
items.append([3, 4])
- Python takes the object
[3, 4]. - It adds that object as one new element at the end.
- The list becomes:
[1, 2, [3, 4]]
print(items)
Real World Use Cases
Building a list of results
If you are collecting one result at a time, append() is usually the right choice.
errors = []
errors.append("Missing email")
errors.append("Password too short")
Merging multiple records
If you already have a list of items and want to add them all to another list, extend() is better.
all_users = ["Ana", "Ben"]
new_users = ["Cara", "Dan"]
all_users.extend(new_users)
Preserving grouped data
Sometimes you intentionally want a nested list. In that case, use append().
rows = []
rows.append([1, 2, 3])
rows.append([4, 5, 6])
This is useful for table-like data where each row should stay grouped.
Combining API or file data
If an API returns a list of records, you often use extend() to combine them into one larger list.
Real Codebase Usage
In real projects, developers choose between append() and extend() based on the intended data shape.
Common patterns
Add one processed item at a time
cleaned = []
for name in raw_names:
cleaned.append(name.strip())
Use append() when each loop iteration produces one final item.
Merge a batch of items
all_logs = []
for batch in log_batches:
all_logs.extend(batch)
Use extend() when each loop iteration produces a list or iterable of many items.
Guard against wrong input shape
def add_tags(existing_tags, new_tags):
if not isinstance(new_tags, list):
raise TypeError("new_tags must be a list")
existing_tags.extend(new_tags)
This avoids accidentally extending with a string or another unexpected iterable.
Building nested structures intentionally
Common Mistakes
1. Using append() when you meant extend()
Broken example:
nums = [1, 2]
nums.append([3, 4])
print(nums)
Output:
[1, 2, [3, 4]]
If you wanted a flat list, use:
nums = [1, 2]
nums.extend([3, 4])
2. Using extend() with a string by accident
Broken example:
words = ["hello"]
words.extend("world")
print(words)
Output:
['hello', 'w', 'o', 'r', 'l', ]
Comparisons
| Feature | append() | extend() |
|---|---|---|
| Adds | One item | Multiple items from an iterable |
| Argument type | Any object | An iterable |
| If given a list | Adds the whole list as one element | Adds each element of the list |
| If given a string | Adds the whole string as one element | Adds each character |
| Resulting structure | Can create nested lists | Usually keeps list flat |
| Modifies list in place | Yes | Yes |
| Return value | None | None |
Cheat Sheet
# Add one item
my_list.append(item)
# Add all items from an iterable
my_list.extend(iterable)
Quick rules
- Use
append()for one item. - Use
extend()for many items from an iterable. append([1, 2])→ adds one nested listextend([1, 2])→ adds1and2append("ab")→ adds one stringextend("ab")→ adds'a'and'b'- Both modify the list in place.
- Both return
None.
Mini examples
x = [1, 2]
x.append(3) # [1, 2, 3]
x = [1, 2]
x.append([3, 4]) # [1, 2, [3, 4]]
x = [, ]
x.extend([, ])
FAQ
Does append() add multiple items in Python?
No. append() always adds exactly one object to the end of the list. That object can itself be a list.
Does extend() create a nested list?
Usually no. extend() takes items from an iterable and adds them one by one, which usually keeps the list flat.
Can I use extend() with a string?
Yes, because a string is iterable. But it will add each character separately, which is often not what beginners expect.
Do append() and extend() return a new list?
No. Both methods modify the original list in place and return None.
When should I use append() instead of extend()?
Use append() when you want to add a single item, including when that single item is another list.
When should I use extend() instead of append()?
Use extend() when you already have multiple items in an iterable and want to add all of them to the list.
Mini Project
Description
Create a simple Python program that builds a playlist. This project demonstrates when to use append() for adding one song and when to use extend() for adding a batch of songs from another list.
Goal
Build a playlist correctly using both append() and extend() so you can see the difference in the final list structure.
Requirements
- Start with a list containing at least two song titles.
- Add one new song using
append(). - Add multiple songs from another list using
extend(). - Print the playlist after each change.
- Also show what happens if you use
append()with a list of songs instead ofextend().
Keep learning
Related questions
@staticmethod vs @classmethod in Python Explained
Learn the difference between @staticmethod and @classmethod in Python with clear examples, use cases, mistakes, and a mini project.
Catch Multiple Exceptions in One except Block in Python
Learn how to catch multiple exceptions in one Python except block using tuples, with examples, mistakes, and real-world usage.
Convert Bytes to String in Python 3
Learn how to convert bytes to str in Python 3 using decode(), text mode, and proper encodings with practical examples.