Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › Python › Reference › extend()

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.

Input:

                
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
iterableiterableElements to add. Must be iterable.
ReturnNoneAlways None — mutates in place.
1

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
2

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."

3

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.

4

Return Value Trap

a = [1, 2]

# ❌ WRONG
a = a.extend([3])
# a is now None!

# ✅ CORRECT
a.extend([3])
# a: [1, 2, 3]
5

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
append1 item (as-is)None
extendMany items (each)None
+Many items (new list)New list
+=Many items (in place)Same list (mutated)

⚠️ Common Mistakes

❓ 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.

🎯 What's Next?

← All Python Reference