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.
Example:
my_list
= [1, 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]
No comments:
Post a Comment