How to Remove First n Elements from List in Python?
Hey Folks,
This tutorial shows you remove first n elements from list python. In this article, we will implement a how to remove first n elements from list in python. Here you will learn python remove n elements from end of list. We will look at an example of python remove first n element from list. Let's get started with python list remove first n elements.
There are several ways to remove the first n numbers of elements from the list in python. we will use del to delete n elements from first in list. Without any further ado, let's see the code examples below.
You can use these examples with python3 (Python 3) version.
Example 1:
main.py
# Create New List with Item myList = [1, 2, 3, 4, 5, 6] n = 2 # Remove N Number of Item from First newList = myList[n:] print(newList)
Output:
[3, 4, 5, 6]
Example 2:
main.py
# Create New List with Item myList = [1, 2, 3, 4, 5, 6] n = 2 # Remove N Number of Item from First del myList[:n] print(myList)
Output:
[3, 4, 5, 6]
I hope it can help you...