Home >>Python List Methods >Python List extend() Method

Python List extend() Method

Python List extend() Method

Python list extend() method is used to add the specified list elements or any iterable to the end of the current list.

Syntax:
list.extend(iterable)

Parameter Values

Parameter Description
iterable This is a required parameter. It defines any iterable.
Here is an example of Python extend() method:

x = ['Abhi', 'Alpha', 'Harry']
y = ['Venom', 'Jerry', 'Rocket']
x.extend(y)
print(x)

Output:
['Abhi', 'Alpha', 'Harry', 'Venom', 'Jerry', 'Rocket']
Example 2:

x = ['Abhi', 'Alpha', 'Harry']
y = ['Venom', 'Jerry', 'Rocket']
z = (1, 2, 3, 4)
x.extend(y)
x.extend(z)
print(x)

Output:
['Abhi', 'Alpha', 'Harry', 'Venom', 'Jerry', 'Rocket', 1, 2, 3, 4]

No Sidebar ads