How to Remove List Element by Value in Python?

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


Hi Guys,

In this tutorial, you will learn How to Remove List Element by Value in Python. you can understand a concept of python list remove element example. you'll learn python list delete element value. let’s discuss about python list remove element by value. Alright, let’s dive into the steps.

In this tutorial, I will give you two examples. one using "remove" function of array and another using "discard" function of array module. you need to pass value 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 = ['one', 'two', 'three', 'four', 'five']
  
# Remove Element
myArray.remove('three')
  
print(myArray)
Output
['one', 'two', 'four', 'five']

Example 2

main.py
import array as arrayLib
   
# Create Array
myArrayObj = arrayLib.array('i', [1, 2, 3, 4, 5, 6])
myArray = set(myArrayObj)
  
# Remove Element
myArray.discard(3)
  
print(myArray)
Output
{1, 2, 4, 5, 6}

It will help you....

Happy Pythonic Coding!