Open In App

Remove Last Element from List in Python

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Given a list, the task is to remove the last element present in the list. For Example, given a input list [1, 2, 3, 4, 5] then output should be [1, 2, 3, 4]. Different methods to remove last element from a list in python are:

  • Using pop() method
  • Using Slicing Technique
  • Using del Operator
  • Using Unpacking Technique
  • Using List Comprehension

Using pop() method

pop() method removes and returns the last element of the list.

Python
a = ["Geeks", "For", "Geeks"]
print(a)

ele = a.pop()
print(a)

Output
['Geeks', 'For', 'Geeks']
['Geeks', 'For']

Explanation: a.pop() removes 'Geeks' from the list and stores it in ele.

Using Slicing Technique

The slicing technique is used to exclude the last element of the list. This method does not modify the original list in place but rather creates a new list.

Python
a = ["Geeks", "For", "Geeks"]
print(a)

a= a[:-1]
print(a)

Output
['Geeks', 'For', 'Geeks']
['Geeks', 'For']

Explanation: Slicing creates a new list by specifying the range of elements to include, excluding the last element by using a[:-1].

Using del operator

del operator can delete the last element from the list along with index.

Python
a = ["Geeks", "For", "Geeks"]
print(a)

del a[-1]
print(a)

Output
['Geeks', 'For', 'Geeks']
['Geeks', 'For']

Explanation: The del statement deletes an element at the specified index. In this case, a[-1] targets the last element, and the list is modified in place.

Using Unpacking Technique

Unpacking technique is used to separate the list into two parts, discarding the last element.

Python
a = ["Geeks", "For", "Geeks"]
print(*a)
*a, _ = a
print(a)

Output
Geeks For Geeks
['Geeks', 'For']

Explanation: Here we have the star(*) operator that unpacks the sequence or iterables into positional arguments. And then underscore(_) ignores the last value and finally assigns it to the list.

Using List comprehension

List comprehension creates a new list by excluding the last element.

Python
a = ["Geeks", "For", "Geeks"]
print(a)

a = [x for x in a[:-1]]
print(a)

Output
['Geeks', 'For', 'Geeks']
['Geeks', 'For']

Explanation: This method uses list comprehension to iterate over the list up to the second-to-last element, excluding the last one (a[:-1]). It returns a new list without modifying the original list in place.


Next Article
Article Tags :
Practice Tags :

Similar Reads