The extend Method in Python: Adding Elements to a List

Enhance a list with elements from a specified iterable object. This modifies the original list in place and returns None.

extend (iterable)

  • iterable -- an object that supports iteration, whose elements are added to the list.
my_list = []
my_list.extend([1, 2, 3])  # my_list becomes [1, 2, 3]
my_list.extend('add')  # my_list becomes [1, 2, 3, 'a', 'd', 'd']

To add a single element, use the append() method.