Get The Most Affordable Hosting in the World!
Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.
Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!
Get Started Now!The list class methods remove() and pop() both can remove an item from a list. The difference between them is that remove() removes the object given as argument, while pop() removes an item at the given index.
Using the remove() Method
The following example shows how you can use the remove() method to remove list items −
It will produce the following output −
Original list: ['Rohan', 'Physics', 21, 69.75] List after removing: ['Rohan', 21, 69.75]
Using the pop() Method
The following example shows how you can use the pop() method to remove list items −
It will produce the following output −
Original list: [25.5, True, -55, (1+2j)] List after popping: [25.5, True, (1+2j)]
Using the "del" Keyword
Python has the "del" keyword that deletes any Python object from the memory.
Example
We can use "del" to delete an item from a list. Take a look at the following example −
It will produce the following output −
Original list: ['a', 'b', 'c', 'd'] List after deleting: ['a', 'b', 'd']
Example
You can delete a series of consecutive items from a list with the slicing operator. Take a look at the following example −
It will produce the following output −
List before deleting: [25.5, True, -55, (1+2j)] List after deleting: [-55, (1+2j)]
The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.