30-Mar-2023
.
Admin
Hi Dev,
we will discuss removing the first n elements from the list in the python example. This tutorial will give you a simple example of removing the first n elements from the list python. I explained simply how to remove the first n elements from list in python. Here you will learn python to remove n elements from the end of the list. So, let's follow a few steps to create an example of python removing first n element from the list.
There are several ways to remove the first n numbers of elements from the list in python. we will use len() to delete n elements from first in list. Without any further ado, let's see the code examples below.
Example :
main.py
# Create New List with Item
myList = [7, 8, 9, 10, 11, 12]
n = 2
# Remove N Number of Item from First
newList = myList[n:]
print(newList)
Output:
[9, 10, 11, 12]
#Python