The del Statement in Python
The del Statement in Python:-
The remove method removes a specific item from a list, if that item is in the list. Some situations might require that you remove an element from a specific index, regardless of the item that is stored at that index. This can be accomplished with the del statement. Here is an example of how to use the del statement:
my-list = [l, 2, 3, 4, 5]
print 'Before deletion:’, my-list
del my-list [2]
print 'After deletion:', my-list
This code will display the following:
Before deletion: [1, 2, 3, 4, 5]
After deletion: [1, 2, 4, 5]
|