ItSolutionStuff.com

How to Remove First Element from List in Python?

By Hardik Savani • October 30, 2023
Python

Hi,

Here, I will show you how to works python list delete first element. This article will give you simple example of python list remove first element. I would like to share with you python list remove one element. you will learn python list remove first n elements.

In this example, I will give you two examples. one using "del" in python and another using "pop" function of array. we will pass first key and it will remove first element from array in python. so let's see below examples.

You can use these examples with python3 (Python 3) version.

let's see below simple example with output:

Example 1:

main.py

myArray = ['one', 'two', 'three', 'four', 'five']
  
# Remove First Element
myArray.pop(0)
  
print(myArray)

Output:

['two', 'three', 'four', 'five']

Example 2:

main.py

myArray = [1, 2, 3, 4, 5, 6]
    
# Remove First Element
del myArray[0]
    
print(myArray)

Output:

[2, 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 List Remove Element by Index Example

Read Now →

How to Get All Files from Directory in Python?

Read Now →

Python Delete Files Matching Pattern Example

Read Now →

Python Delete Folder and Files Recursively Example

Read Now →

Python Delete Files with Specific Extension Example

Read Now →

Python Delete Directory if Exists Example

Read Now →

Python Post Request with Basic Authentication Example

Read Now →

Python Get First Date of Last Month Example

Read Now →

Python Get First Date of Next Month Example

Read Now →

Python Create Zip Archive from Directory Example

Read Now →

How to Compare Two Dates in Python?

Read Now →

How to Check if Today is Saturday or not in Python?

Read Now →