What is the syntax to delete a list element?

#to delete one element
del <list name>[<index>]

#to delete many elements
del <list name>[<start index, inclusive>:<end index, exclusive>]
#example
>>> letters = ['A','B','C','D','E']

>>> del letters[0]
>>> letters
['B', 'C', 'D', 'E']

>>> del letters[2:4]
>>> letters
['B', 'C']

 

Advertisements