Remove Last Element from List in Python
Last Updated :
26 Apr, 2025
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)
OutputGeeks 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.
Similar Reads
Remove first element from list in Python The task of removing the first element from a list in Python involves modifying the original list by either deleting, popping, or slicing the first element. Each method provides a different approach to achieving this. For example, given a list a = [1, 2, 3, 4], removing the first element results in
2 min read
How to Remove Item from a List in Python Lists in Python have various built-in methods to remove items such as remove, pop, del and clear methods. Removing elements from a list can be done in various ways depending on whether we want to remove based on the value of the element or index.The simplest way to remove an element from a list by i
3 min read
Remove falsy values from a list in Python Removing falsy values from a list filters out unwanted values like None, False, 0 and empty strings, leaving only truthy values. It's useful for data cleaning and validation.Using List ComprehensionList comprehension is a fast and efficient way to remove falsy values from a list . It filters out val
1 min read
Remove empty tuples from a list - Python The task of removing empty tuples from a list in Python involves filtering out tuples that contain no elements i.e empty. For example, given a list like [(1, 2), (), (3, 4), (), (5,)], the goal is to remove the empty tuples () and return a new list containing only non-empty tuples: [(1, 2), (3, 4),
3 min read
Ways to remove particular List element in Python There are times when we need to remove specific elements from a list, whether itâs filtering out unwanted data, deleting items by their value or index or cleaning up lists based on conditions. In this article, weâll explore different methods to remove elements from a list.Using List ComprehensionLis
2 min read
Remove all the occurrences of an element from a list in Python The task is to perform the operation of removing all the occurrences of a given item/element present in a list. Example Input1: 1 1 2 3 4 5 1 2 1 Output1: 2 3 4 5 2 Explanation : The input list is [1, 1, 2, 3, 4, 5, 1, 2] and the item to be removed is 1. After removing the item, the output list is [
4 min read
Remove all values from a list present in another list - Python When we work with lists in Python, sometimes we need to remove values from one list that also exists in another list. Set operations are the most efficient method for larger datasets. When working with larger lists, using sets can improve performance. This is because checking if an item exists in a
3 min read
Remove Key from Dictionary List - Python We are given a list of dictionaries and our task is to remove a specific key from each dictionary in the list. For example, if we have the following list: li = [{'Gfg': 1, 'id': 2, 'best': 8}, {'Gfg': 4, 'id': 4, 'best': 10}, {'Gfg': 4, 'id': 8, 'best': 11}] and the key to remove is "id" then the re
3 min read
Python - Print list after removing element at given index In this article, we will explore different ways to remove an element from a list at a given index and print the updated list, offering multiple approaches for achieving this.Using pop()pop() method removes the element at a specified index and returns it.Pythonli = [10, 20, 30, 40, 50] index = 2 li.p
2 min read
Remove items from Set - Python We are given a set and our task is to remove specific items from the given set. For example, if we have a = {1, 2, 3, 4, 5} and need to remove 3, the resultant set should be {1, 2, 4, 5}.Using remove()remove() method in Python is used to remove a specific item from a set. If the item is not present
2 min read