
List pop (Python) - How to delete or remove from list by index
pop
removes the element from a list in Python. pop(1)
means deleting the second item from a list.
x = ['a', 'b', 'c', 'd']
x.pop(1)
print(x) # ['a', 'c', 'd']
pop
takes only one argument so the following is incorrect.
x = ['a', 'b', 'c', 'd']
x.pop(1, 2)
# TypeError: pop expected at most 1 argument, got 2
Comments
Powered by Markdown