Python extension list

Extending Lists in Python

The `extend()` method of the `list` class increases the size of a list by appending the items in the given list to the end of the list.

Syntax

list.extend(x)

Parameters

x: an iterable to be appended to the original list

Return Value

This method does not return any value because the list is extended in place.

Example

The following example demonstrates how to extend a list:

lst = ['Bina', 'Arun', 'Bharat', 'Tim', 'Biplov']
print ("lst:", lst)
lst.extend(['Kiran', 'Sunil'])
print ("new list", lst)

This will produce the following output:

lst: ['Bina', 'Arun', 'Bharat', 'Tim', 'Biplov']
new list ['Bina', 'Arun', 'Bharat', 'Tim', 'Biplov', 'Kiran', 'Sunil']

Leave a Reply

Your email address will not be published. Required fields are marked *