Python Extending a List
The extend() method of the list class increases the size of the list by appending the items in a given list.
Syntax
list.extend(x)
Parameters
x: an iterable to be appended to the original list
Return Value
The method doesn't return anything, as the list is extended in place.
Example
The following example demonstrates how you can extend a list −
lst = ['Bina', 'Arun', 'Bharat', 'Tim', 'Biplov']
print ("lst:", lst)
lst.extend(['Kiran', 'Sunil'])
print ("new list", lst)
It will produce the following output −
lst: ['Bina', 'Arun', 'Bharat', 'Tim', 'Biplov'] new list ['Bina', 'Arun', 'Bharat', 'Tim', 'Biplov', 'Kiran', 'Sunil']
python_list_methods.htm
Advertisements