PythonArraysBeginner

list.extend()

Adds all items from an iterable to the end of a list (mutates).

Review the syntaxStudy the examplesOpen the coding app
my_list.extend(iterable)

This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.

What it does

Overview

Adds all items from an iterable to the end of a list (mutates).

The extend() method iterates over the specified iterable (such as a list, tuple, set, or string) and appends each element to the end of the current list. This operation modifies the list in-place and returns None, which is a common source of bugs for developers expecting a new list. In terms of performance, extend() is generally more efficient than repeated calls to append() because it allows the underlying array to resize more efficiently if the size of the iterable is known. The time complexity is O(k), where k is the length of the iterable being added. A notable edge case occurs when passing a string: since strings are iterables in Python, extend() will append each character individually rather than the whole string as a single unit.

Quick reference

Syntax

my_list.extend(iterable)

Inputs

Parameters

iterableIterable[Any] · Items to add (e.g., list, tuple, set).

See it in practice

Examples

1

Merging Two Lists

fruits = ['apple', 'banana']
more_fruits = ['cherry', 'date']
fruits.extend(more_fruits)
print(fruits)
Output:
['apple', 'banana', 'cherry', 'date']

Standard usage to flatten and add elements from one list to another.

2

Extending with a Tuple

numbers = [1, 2, 3]
coords = (4, 5)
numbers.extend(coords)
print(numbers)
Output:
[1, 2, 3, 4, 5]

Demonstrates that extend() accepts any iterable, including tuples.

3

The String Iteration Behavior

tags = ['python', 'code']
tags.extend('web')
print(tags)
Output:
['python', 'code', 'w', 'e', 'b']

Strings are iterables; extend() adds each character individually. Use append() if the whole string is needed.

Debug faster

Common Errors

1

TypeError

Cause: Passing a non-iterable object (like an integer or None) to the extend() method.

Fix: Ensure the argument is a list, tuple, or other iterable, or use append() for single non-iterable items.

items = [1, 2]
items.extend(3) # Raises TypeError
2

LogicError

Cause: Assigning the result of extend() to a variable, expecting a new list.

Fix: Call extend() on its own line; it modifies the list in-place and returns None.

my_list = [1, 2]
new_list = my_list.extend([3, 4])
print(new_list) # Output: None

Runtime support

Compatibility

Python 3.8+

Source: MDN Web Docs

Common questions

Frequently Asked Questions

Adds all items from an iterable to the end of a list (mutates).

iterable: Items to add (e.g., list, tuple, set).

TypeError: Ensure the argument is a list, tuple, or other iterable, or use append() for single non-iterable items. LogicError: Call extend() on its own line; it modifies the list in-place and returns None.