ItSolutionStuff.com

How to Remove First n Elements from List in Python?

By Hardik Savani • October 30, 2023
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...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Python Pretty Print List of Dictionaries Example

Read Now →

How to Check If Element is Present in List Python?

Read Now →

Python Read Text File into List Example

Read Now →

Python List Add Element at Beginning Example

Read Now →

How to Add Element at the End of List in Python?

Read Now →

How to Add Element at Specific Index in Python List?

Read Now →

How to Count Number of Elements in a List in Python?

Read Now →

Python List Print All Elements Except First Example

Read Now →

How to Get Min Value from Python List?

Read Now →

How to Convert List to Capitalize First Letter in Python?

Read Now →

How to Convert List to Lowercase in Python?

Read Now →

Python Split String into List of Characters Example

Read Now →

How to Convert String into List in Python?

Read Now →