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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
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?