There are three methods to remove elements from a list:
The list includes a built-in method for Python called removes (). Removing the first element that matches the given criteria from the list is helpful.
Syntax:
list.remove(element)
The element that you want to remove from the list.
ReturnValue
There is no return value for this method.
For instance,
List = ['A', 'E', 'I', 'O','U']
List.remove('I')
print(List)
Output:
['A', 'E', 'O', 'U']
Example:
List = ["CAT",11,22,33,"JAVA",22,33,11]
List.pop(1)
print(List)
Output:
['CAT', 22, 33, 'JAVA', 22, 33, 11]
With one exception, this operator differs significantly from the pop() method of the List object. The item or element at the specified index location is removed from the list by the del operator, but unlike the pop() method, the item is not returned.
Example:
List = ["CAT",11,22,33,"JAVA",22,33,11]
del List[1]
print(List)
Output:
['CAT', 22, 33, 'JAVA', 22, 33, 11]
Note: also read about Iterate over a list in Python
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
You are given two singly linked lists that intersect at some node. Your task is…
A builder plans to construct N houses in a row, where each house can be…
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…