Javatpoint Logo
Javatpoint Logo

Python List extend() Method

Python extend() method extends the list by appending all the items from the iterable. Iterable can be a List, Tuple or a Set. Examples are described below.

Signature

Parameters

x: Iterable type parameter.

Return

It does not return any value rather modifies the list.

Let's see some examples of extend() method to understand it's functionality.

Python List extend() Method Example 1

It is a simple example to describe the use of extend method.

Output:

1
2
3
After extending:
1
2
3
4

Python List extend() Method Example 2

We can pass list as an element and the list will be extended. See the example below.

Output:

1
2
3
After extending:
1
2
3
4
5
6

Python List extend() Method Example 3 : Tuple

It can be possible that the element is a tuple type and the list extends itself by tuple elements. See the example below.

Output:

1
2
3
After extending:
1
2
3
4
5
6

Python List extend() Method Example : Set

It can be possible that the element is a Set type and the list extends itself by Set elements. See the example below.

Output:

1
2
3
After extending:
1
2
3
6
5
4

Next TopicPython Lists




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA