+1 vote
in Class 12 by kratos

Give an example to remove list element.

1 Answer

+4 votes
by kratos
 
Best answer

To remove a list element, you can use either I the del statement if you know exactly which ‘ element(*) you are deleting or the remove I ( ) method if you do not know. Following is a simple example:

!/user/bin/python

list1 = [‘physics’, ‘chemistry’, 1997, 2000];

print list1;

del list1 [2];

print “After deleting value at index 2 :”

print list1;

When the above code is **, it produces the following result:**

[‘physics’, ‘chemistry’, 1997, 2000];

After deleting value at index 2;

[‘physics’, ‘chemistry’, 2000]

...