Skip to content
Related Articles

Related Articles

Improve Article
How to remove an item from the List in Python?
  • Last Updated : 29 Aug, 2020

Python Lists have various in-built methods to remove items from the list. Apart from these, we can also use del statement to remove an element from the list by specifying a position. Let’s look at these methods –

Method 1: Using del statement
The del statement is not a function of List. Items of the list can be deleted using del statement by specifying the index of item (element) to be deleted.




# Python 3 code to
# remove an item from list
# using del statement
  
lst = ['Iris', 'Orchids', 'Rose', 'Lavender',
       'Lily', 'Carnations']
print("Original List is :", lst)
  
# using del statement
# to delete item (Orchids at index 1) 
# from the list
del lst[1]
print("After deleting the item :", lst)

Output:

Original List is : [‘Iris’, ‘Orchids’, ‘Rose’, ‘Lavender’, ‘Lily’, ‘Carnations’]
After deleting the item : [‘Iris’, ‘Rose’, ‘Lavender’, ‘Lily’, ‘Carnations’]

Method 2: Using remove()
We can remove an item from the list by passing the value of the item to be deleted as the parameter to remove() function.






# Python 3 code to
# remove an item from list
# using function remove()
  
lst = ['Iris', 'Orchids', 'Rose', 'Lavender',
       'Lily', 'Carnations']
print("Original List is :", lst)
  
# using remove()
# to delete item ('Orchids') 
# from the list
lst.remove('Orchids')
print("After deleting the item :", lst)

Output:

Original List is : [‘Iris’, ‘Orchids’, ‘Rose’, ‘Lavender’, ‘Lily’, ‘Carnations’]
After deleting the item : [‘Iris’, ‘Rose’, ‘Lavender’, ‘Lily’, ‘Carnations’]

Method 3: Using pop()
pop() is also a method of list. We can remove the element at the specified index and get the value of that element using pop().




# Python 3 code to
# remove an item from list
# using function pop()
  
lst = ['Iris', 'Orchids', 'Rose', 'Lavender'
       'Lily', 'Carnations']
print("Original List is :", lst)
  
# using pop()
# to delete item ('Orchids' at index 1) 
# from the list
a = lst.pop(1)
print("Item popped :", a)
print("After deleting the item :", lst)

Output –

Original List is : [‘Iris’, ‘Orchids’, ‘Rose’, ‘Lavender’, ‘Lily’, ‘Carnations’]
Item popped : Orchids
After deleting the item : [‘Iris’, ‘Rose’, ‘Lavender’, ‘Lily’, ‘Carnations’]

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :