Python Function Reference

list.extend

Add all the items of an iterable to the end of the list.

Python 3.13
list.extend(iterable)

Parameters

iterableIterable
The items to add.

Return value

Nothing (None); the list is changed in place.

Examples

Adding items from another list

Python 3.13
a = [1, 2]
a.extend([3, 4])
print(a)
[1, 2, 3, 4]

A string is added character by character

Python 3.13
a = [1]
a.extend('ab')
print(a)
[1, 'a', 'b']

Details

Any iterable is unpacked into items: a string into characters, a dictionary into keys. a += [3, 4] works the same way as a.extend([3, 4]).

See also

Where to learn