How to Remove List Element by Index in Python?

Published On: 05/11/2022 | Category: Python


Hi Guys,

In this tutorial, I will show you how to remove list element by index in python. if you want to see example of python list remove element example then you are a right place. step by step explain python list delete element index. We will look at example of python list remove element by index. you will do the following things for python list remove element by index.

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

So let's see bellow example:

Example 1

main.py
myArray = [1, 2, 3, 4, 5, 6]
  
# Remove Element
del myArray[2]
  
print(myArray)
Output
[1, 2, 4, 5, 6]

Example 2

main.py
myArray = [1, 2, 3, 4, 5, 6]
  
# Remove Element
myArray.pop(2)
  
print(myArray)
Output
[1, 2, 4, 5, 6]

It will help you....

Happy Pythonic Coding!