How to Remove First n Elements from List in Python?
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.
# 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)
[3, 4, 5, 6]
# 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)
[3, 4, 5, 6]
I hope it can help you...
We are Recommending you
- Python Pretty Print List of Dictionaries Example
- How to Check If Element is Present in List Python?
- Python Read Text File into List Example
- Python List Add Element at Beginning Example
- How to Add Element at the End of List in Python?
- How to Add Element at Specific Index in Python List?
- How to Count Number of Elements in a List in Python?
- Python List Print All Elements Except First Example
- How to Get Min Value from Python List?
- How to Convert List to Capitalize First Letter in Python?
- How to Convert List to Lowercase in Python?
- Python Split String into List of Characters Example
- How to Convert String into List in Python?