How to remove element from list in python?
![](https://pythonpoint.net/wp-content/uploads/2020/11/What-is__init__-in-python_-7-1024x576.jpg)
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.
e.g.,
l=[1,2,3,4,5,6,7,8,9] del l[4] l
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-697-1024x376.png)
- pop()- This is used to remove single element from the list.
e.g.,
l=[1, 2, 3, 4, 5] a=l.pop(1) print(a) print(l)
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-699-1024x304.png)
- remove()- The remove() removes the first occurrence of given item from the list.
e.g.,
t=['a','b','c','d','e'] t.remove('b') print(t)
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-701-1024x265.png)
This is all about removing element from the list.
Subscribe
Login
Please login to comment
0 Discussion