Skip to content
Home » Python Programs » Python Program to Remove an Element from a List

Python Program to Remove an Element from a List

Python Program to Remove an Element from a List. This program will delete the number in list which is already listed in list data structure in python programming language. These data structure concepts are very important those who are trying to get a job in python developer.

List in Python

Multiple items can be stored in a single variable using lists. Lists are one of four built-in Python data types for storing collections of data; the other three are Tuple, Set, and Dictionary, all of which have different qualities and applications. A list is made in Python by putting elements inside square brackets [] and separating them with commas. There can be any number of items on a list, and they can be of various types. Another list can be included as an item in a list. This is referred to as a nested list.

List Operators in Python

The operations that can be performed on the data in the list data structure are known as list operations. extend(), insert(), append(), remove(), pop(), Slice, Reverse(), min() & max(), concatenate(), count(), multiply(), sort(), index(), clear(), and others are some of the basic list operations used in Python programming.

del() Keyword in Python

In Python, the del keyword is mostly used to remove objects. Because everything in Python is an object, the del keyword may be used to delete a list, slice a list, delete dictionaries, remove key-value pairs from dictionaries, delete variables, and so on.

To delete an element by value, use del to delete it by index, pop() to delete it by index if you require the returned value, and remove() to delete it by value. The latter involves scanning the list, and if no such value is found, it generates a ValueError. 

Python Program to Remove an Element from a List

list = [10,20,30,40,50,60]
del list[2]
print(list)
del list

Output:

[10, 20, 40, 50, 60]