list.extend()

list.extend(iterable)
Returns: None · Updated March 14, 2026 · List Methods
lists methods mutation

The .extend() method adds all elements from an iterable to the end of a list. It modifies the list in-place and returns None, meaning you never assign its result to a variable. This is the idiomatic way to merge two lists or add elements from any iterable (tuples, sets, strings, generators) into an existing list.

Syntax

list.extend(iterable)

Parameters

ParameterTypeDefaultDescription
iterableiterableAn iterable (list, tuple, set, string, generator, etc.) whose elements will be added to the list.

Return Value

Returns None. The list is modified in-place.

Examples

Basic usage - extending with another list

Add elements from one list to another:

fruits = ["apple", "banana"]
fruits.extend(["cherry", "date"])
print(fruits)
# ['apple', 'banana', 'cherry', 'date']

Extending with a tuple

Tuples work just like lists:

numbers = [1, 2, 3]
numbers.extend((4, 5, 6))
print(numbers)
# [1, 2, 3, 4, 5, 6]

Extending with a set

Sets are unordered but work for adding unique elements:

unique = [1, 2, 3]
unique.extend({4, 5, 6})
print(unique)
# [1, 2, 3, 4, 5, 6]

Extending with a string

Strings are iterable — extending with a string adds each character:

letters = ["a", "b"]
letters.extend("cd")
print(letters)
# ['a', 'b', 'c', 'd']

# If you want to add the whole string as one element, use .append()
letters = ["a", "b"]
letters.append("cd")
print(letters)
# ['a', 'b', 'cd']

Extending with a generator

Generators work efficiently without loading everything into memory first:

def generate_numbers(n):
    for i in range(n):
        yield i * 2

numbers = [1, 2, 3]
numbers.extend(generate_numbers(5))
print(numbers)
# [1, 2, 3, 0, 2, 4, 6, 8]

Extending with a range

The range() object is iterable and useful for adding sequences:

sequence = [0, 1, 2]
sequence.extend(range(3, 8))
print(sequence)
# [0, 1, 2, 3, 4, 5, 6, 7]

Common Patterns

Merging two lists

The most common use case is merging lists:

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)
# [1, 2, 3, 4, 5, 6]

# Equivalent but less idiomatic:
# list1 = list1 + list2  # creates a new list

Building a list from multiple sources

Extend works with any combination of iterables:

result = []
result.extend([1, 2, 3])      # start with a list
result.extend((4, 5))         # add a tuple
result.extend({6, 7})          # add a set
result.extend("hi")           # add characters from string
result.extend(range(10, 12))   # add from range
print(result)
# [1, 2, 3, 4, 5, 6, 7, 'h', 'i', 10, 11]

Filtering and extending in one step

A useful pattern combines filtering with extension:

source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
target = []
target.extend(x for x in source if x % 2 == 0)
print(target)
# [2, 4, 6, 8, 10]

The difference between append and extend

Understanding when to use each is crucial:

# .append() adds a single element
data = [1, 2, 3]
data.append([4, 5])
print(data)
# [1, 2, 3, [4, 5]]  — nested list

# .extend() adds each element
data = [1, 2, 3]
data.extend([4, 5])
print(data)
# [1, 2, 3, 4, 5]  — flattened

Performance Note

  • .extend() with a list is O(k) where k is the length of the added iterable
  • It’s more efficient than using += repeatedly in a loop
  • For very large iterables, using a generator expression avoids creating an intermediate list in memory
# Efficient: generator doesn't create intermediate list
large_list = []
large_list.extend(x for x in range(1000000))

See Also