Python list - extend method

Extend a python list object by adding another existing python list object

List Updated 11 Sep 2016 1 min read

Method Name

extend

Method Signature

extend(anotherlist_in)

Method Overview

The extend() method appends an existing list object as specified by the parameter anotherlist_in to the python list.

Parameters

anotherlist_in: An existing Python list object which is to be appended to the list object.

Exceptions

None

Example

python
# Example Python program that extends

            # an existing list with the contents from another list

            l1 = ["Philosopher's Stone", "Chamber of Secrets", "Prisoner of Azkaban"]

            l2 = ["Goblet of Fire", "Order of the Phoenix", "Half-Blood Prince", "Deathly Hallows"]

            l1.extend(l2)

            print(l1)

Output

Output
["Philosopher's Stone", 'Chamber of Secrets', 'Prisoner of Azkaban', 'Goblet of Fire', 'Order of the Phoenix', 'Half-Blood Prince', 'Deathly Hallows']