Delete List Elements in python

everytopichub
0

 4.5 Delete List Elements 

To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know. 

For example 

− list1 = ['physics', 'chemistry', 1997, 2000];

 print list1 del list1[2]; 

print "After deleting value at index 2 : " print list1 

When the above code is executed, it produces following result

 − ['physics', 'chemistry', 1997, 2000]

 After deleting value at index 2 : ['physics', 'chemistry', 2000] 

Note − remove() method is discussed in subsequent section.

Post a Comment

0Comments

Post a Comment (0)