Python list extend() method
Add every item from another collection to the end.
Syntax
list.extend(iterable)
Unlike append, which would add the whole list as a single item.
Parameters
| iterable | the items to add |
Return value
None
Example
Code
a = [1, 2] a.extend([3, 4]) print(a) b = [1, 2] b.append([3, 4]) print(b) # one item, which is a list print([1, 2] + [3]) # + makes a new list instead
Output
[1, 2, 3, 4] [1, 2, [3, 4]] [1, 2, 3]
Related
Learn it step by step in the free lesson Lists & Tuples, with exercises that check your answers.