Python Reference
list.extend()
Add multiple elements from an iterable to the end of a list.
Last updated: October 2026
Definition: list.extend(iterable) adds all elements from an iterable to the end of a list. It modifies the list in place and returns None. Each element from the iterable is added individually.
🎬 Live Example
Five common extend patterns. Click any button to see the output.
💡 extend adds many items. append adds one. Never mix them up.
Basic Syntax
list.extend(iterable)
# iterable — any iterable (list, tuple, set, str)
# Mutates list in place
# Returns None
# Adds each element from iterable individually
🎯 Parameters & Return
| Item | Type | Description |
|---|---|---|
iterable | iterable | Elements to add. Must be iterable. |
| Return | None | Always None — mutates in place. |
Basic Extend
a = [1, 2]
a.extend([3, 4])
# a: [1, 2, 3, 4]
a.extend((5, 6))
# a: [1, 2, 3, 4, 5, 6]
a.extend({7, 8})
# order not guaranteed with sets
extend vs append
a = [1, 2]
a.append([3, 4])
# [1, 2, [3, 4]] ← adds as ONE nested list
b = [1, 2]
b.extend([3, 4])
# [1, 2, 3, 4] ← adds each element
Remember: append = "add this item." extend = "add all items from this iterable."
Extending with a String
a = ["hi"]
a.extend("bye")
# ['hi', 'b', 'y', 'e']
# Strings are iterables of characters
# To add the whole string, use append:
b = ["hi"]
b.append("bye")
# ['hi', 'bye']
Watch out: extend("abc") adds 3 characters, not 1 string. Use append to add the whole string.
Return Value Trap
a = [1, 2]
# ❌ WRONG
a = a.extend([3])
# a is now None!
# ✅ CORRECT
a.extend([3])
# a: [1, 2, 3]
Real-World: Merge API Results
all_users = []
for page in range(1, 4):
users = fetch_page(page) # returns a list
all_users.extend(users)
# All users across pages in one flat list
extend is the standard way to accumulate lists across iterations.
🎯 extend vs append vs + vs +=
| Method | Adds | Returns |
|---|---|---|
append | 1 item (as-is) | None |
extend | Many items (each) | None |
+ | Many items (new list) | New list |
+= | Many items (in place) | Same list (mutated) |
⚠️ Common Mistakes
- Assigning the return value.
a = a.extend(b)sets a to None. - Using extend when you meant append. extend iterates; append doesn't.
- Extending with a non-iterable.
a.extend(5)raises TypeError. Use append. - Extending with a string. Adds characters, not the whole string.
- Expecting a new list. extend mutates in place. Use
a + bfor a new list.
❓ Frequently Asked Questions
What does extend() do in Python?
list.extend(iterable) adds all elements from an iterable to the end of a list. It modifies the list in place and returns None.
What is the difference between append and extend?
append adds its argument as a single element. extend iterates over its argument and adds each element individually. append([1,2]) adds one nested list; extend([1,2]) adds two items.
What is the difference between extend and +?
extend modifies the original list in place and returns None. + creates a new list. Use extend for in-place mutation, + or += when you want a new list or reassignment.
Does extend accept strings?
Yes, but it adds each character individually. 'abc'.extend adds 'a', 'b', 'c'. Wrap in a list if you want the whole string as one element.
Does extend return the list?
No. extend returns None. It mutates the list in place. Writing my_list = my_list.extend(x) will set my_list to None.