Works for n >= 1
>>> L = [1,2,3, 4, 5]
>>> n=2
>>> del L[-n:]
>>> L
[1, 2, 3]
Answer from jamylak on Stack Overflow Top answer 1 of 7
135
Works for n >= 1
>>> L = [1,2,3, 4, 5]
>>> n=2
>>> del L[-n:]
>>> L
[1, 2, 3]
2 of 7
52
if you wish to remove the last n elements, in other words, keep first len - n elements:
lst = lst[:len(lst)-n]
Note: This is not an in memory operation. It would create a shallow copy.
05:06
Python List - how to delete elements from a list - YouTube
09:20
Remove multiple elements from a Python List | How to remove multiple ...
06:15
Python: Remove Items from List | 3 ways - pop, del, remove - YouTube
05:16
How to remove the last element in any array or list in python {python ...
01:38
Remove multiple elements from a Python List - YouTube
Reddit
reddit.com โบ r/learnpython โบ delete last two variables from each list 'item'
r/learnpython on Reddit: delete last two variables from each list 'item'
February 5, 2023 - Use a list comprehension creating tuples with the last 2 elements sliced out.
GeeksforGeeks
geeksforgeeks.org โบ python-remove-last-k-elements-of-list
Remove last K elements of list - Python - GeeksforGeeks
January 18, 2025 - Another approach is to use the pop() method. This method removes the last element from the list.
FavTutor
favtutor.com โบ blogs โบ remove-last-element-from-list-python
Remove Last Element from List in Python | FavTutor
October 12, 2023 - When it comes to quick storing and manipulating data while programming, Python lists are one of the most commonly utilized sequential data structures. Lists are a type of collection that greatly simplifies the lives of programmers. Removing the last element from a list excludes the last element of a list by shortening the list. For example, if the given list is [1, 2, 3, 4], then the list after the removal of the last element is [1,2,3]. This removal operation reduces the length of the list by one.
How to Use Linux
howtouselinux.com โบ home โบ 3 ways to remove the last element from list in python
3 ways to remove the last element from list in Python - howtouselinux
October 9, 2025 - The syntax for this is as follows: list[:-1]. For example, if we have a list of integers called my_list, we can remove the last element by using the following code: my_list = [1, 2, 3] my_list[:-1] # Returns [1, 2] # list slicing is a common practice and it is the most used technique for ...
Javatpoint
javatpoint.com โบ how-to-delete-the-last-element-in-a-list-in-python
How to delete the last element in a list in Python - Javatpoint
How to delete the last element in a list in Python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
w3resource
w3resource.com โบ python-exercises โบ list โบ python-data-type-list-exercise-172.php
Python: Remove the last N number of elements from a given list - w3resource
Original lists: [2, 3, 9, 8, 2, 0, 39, 84, 2, 2, 34, 2, 34, 5, 3, 5] Remove the last 3 elements from the said list: [2, 3, 9, 8, 2, 0, 39, 84, 2, 2, 34, 2, 34] Remove the last 5 elements from the said list: [2, 3, 9, 8, 2, 0, 39, 84, 2, 2, 34] Remove the last 1 element from the said list: [2, 3, 9, 8, 2, 0, 39, 84, 2, 2, 34, 2, 34, 5, 3] ... Write a Python program to remove the last N elements from a list and return the removed portion as a new list.
Real Python
realpython.com โบ remove-item-from-list-python
How to Remove Items From Lists in Python โ Real Python
October 21, 2025 - If you donโt pass an index argument to the method call, then .pop() will remove and return the last item in the list. Note that Python lists use zero-based indexing for positioning, which means that the first element in a list is at index 0, the second element is at index 1, and so on.