Let's take a list of elements of a string as an example, and delete the elements:
>>> l = [‘no surfing‘, ‘flippers‘]
Law One: Remove (val)
>>> l.remove(‘no surfing‘)>>> l[‘flippers‘]
- (1) The parameter of remove () is a specific element value, not an index,
(2) If you know the index, how to use Remove to delete the element value on the index,
l.remove(l[1])
This is a great risk because list allows duplicates, remove () delete the first element in the list and the value of the parameter equal
Law II: Pop (0)
(1) the pop () receives the index, and the last element (typical stack ) is deleted without reference.
(2) Pop () has a return value, which returns the value of the deleted element
l.pop() <==> l.pop(-1)
(3) List of append () (added to the tail), pop () (ejected from the tail), successfully changed the list to a stack
Law III: Del (l[0])
>>> del(l[0])
Python Tips (iii)--list three ways to delete an element