In this post, you will learn How to delete items from a list based on position.
del in Python –
If you know the position of an item in a list, you can remove it using del statement.
In : companies = ['Google','Apple','Microsoft','Netflix', 'Facebook']
Let’s say you want to delete the first item from the list.
In : del companies In : companies Out: ['Apple', 'Microsoft', 'Netflix', 'Facebook']
You can remove any item from the list using del statement if you know the index of the item inn the list.
To delete the last item from the list
In : del companies[-1] In : companies Out: ['Apple', 'Microsoft', 'Netflix']
Once you delete an item from a list using del statement you can not access that item again.