Python 3 reference · List Methods
Python List extend() Method
Add every item from an iterable to the end of the list, in place. Like append() for many items at once.
Python 3 Since 3.0
Syntax
list.extend(iterable)
Parameters
| Parameter | Description |
|---|---|
iterable |
Any iterable: list, tuple, set, string, generator, … |
Return value
None.
Examples
numbers = [1, 2]
numbers.extend([3, 4])
numbers.extend(range(5, 7))
print(numbers)
Output
[1, 2, 3, 4, 5, 6]
letters = ["a"]
letters.extend("bc") # a string is iterable: adds characters
print(letters)
print([1, 2] + [3]) # + makes a new list instead
Output
['a', 'b', 'c'] [1, 2, 3]
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
list.append()· Add one item to the end of a list, changing the list in place. Returns None.list.insert()· Insert an item at a given position, shifting later items to the right. Index 0 adds to the front.- Python Lists · tutorial