Delete the list element in python

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 = [10,20,30,40,50,60]
del list[2]
print(list)
del list

 

Output:

[10, 20, 40, 50, 60] 

What is 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.