How to remove element from list in python?
The python lists are containers that are used to store a list of values of any type. Unlike other variables python lists are mutable i.e., we can change the elements of a list in place.
Here we’ll learn how to remove element from list.
There are different ways to do this.
- del()- It is used to delete the element from a list by their index number.
l=[1,2,3,4,5,6,7,8,9] del l l
- pop()- This is used to remove single element from the list.
l=[1, 2, 3, 4, 5] a=l.pop(1) print(a) print(l)
- remove()- The remove() removes the first occurrence of given item from the list.
t=['a','b','c','d','e'] t.remove('b') print(t)
This is all about removing element from the list.
Please login to comment
View all comments