list.pop([i])
‘pop’ method
without argument removes last element in the list. If you specify the position
‘i’, it removes the element at position ‘i’ and return it.
list=[2, 4, 6, 6, 4, 2] print(list) print("Removing last element ", list.pop()) print(list) print("Removing element at index 2 ", list.pop(2)) print(list)
$ python3
test.py
[2, 4, 6, 6,
4, 2]
Removing
last element 2
[2, 4, 6, 6,
4]
Removing
element at index 2 6
[2, 4, 6, 4]
No comments:
Post a Comment