How to remove the first item with the specified value in a list in Python

You can remove the first item with the specified value in a list in Python by following the given step. If you want to learn Python then I will highly recommend you to read This Book.

How to remove the first item with the specified value in a list in Python
How to remove the first item with the specified value in a list in Python

Step 1

Remove method is used to remove the first item with the specified value in a list in Python. In the following example, I will remove integer ‘4’ from the list that will come first in a list.

a = [1,2,3,1,7,4,8,9,4,21]
print(a)
a.remove(4)
print(a)

Example: In case of String

a = ['x','y','c','z','a','b','c']
print(a)
a.remove('c')
print(a)

People are also reading:

What is Computer Vision? Examples, Applications, Techniques

Top 10 Python Books | Best Python Books

Top 10 Computer Vision Books

Leave a Comment

Your email address will not be published.