remove() – delete a list entry by value

List elements can be deleted in Python with the remove() function and specification of the index.

Code Explanation

LineDescription
1Declaration and initialization of the list myList with the values 1, 2, 2, 3 and 4
2The remove(2) method removes the first 2 in the list
4 + 5With the for loop each list element is output
myList = [1, 2, 2, 3, 4]
myList.remove(2)

for i in myList:
    print(i, end=" ")
Output
1 2 3 4