all Python 3Lists (list)function
list.extend
adding
Append all items from an iterable to the end of the list (in place).
Syntax
lst.extend(iterable)
extend iterates over its argument, so a string is split into individual characters — use append if you want the whole string as one element. It works in place and returns None; lst += iterable does exactly the same, whereas lst = lst + other demands a list and builds a new object.
Examples
lst = [1, 2]
lst.extend([3, 4])
print(lst) # → [1, 2, 3, 4]
lst.extend('ab')
print(lst) # → [1, 2, 3, 4, 'a', 'b']
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy