Javatpoint Logo
Javatpoint Logo

Python List pop() Method

Python pop() element removes an element present at specified index from the list. It returns the popped element. The syntax and signature is described below.

Signature

Parameters

x : Element to be popped. It is optional.

Return

It returns popped element.

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

Python List pop() Method Example 1

Let's first see a simple example of popping element from the list. Element present at the index 2 is popped, see the example below.

Output:

1
2
3
After poping:
1
2

Python List pop() Method Example 2

The index is optional, if we don't specify the index, it pops element presents at the last index of the list. See the example below.

Output:

1
2
3
After poping:
1
2

Python List pop() Method Example 3

If the index is a negative value, it will pop element from the right of the list. See the example below.

Output:

1
2
3
After poping:
1
3

Next TopicPython Lists




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA