Remove first element of list
- pop
- shift
To remove an element by its index, use the slice syntax:
names = ['foo', 'bar', 'baz', 'moo']
first = names.pop(0)
print(first) # foo
print(names) # ['bar', 'baz', 'moo']
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
To remove an element by its index, use the slice syntax:
names = ['foo', 'bar', 'baz', 'moo']
first = names.pop(0)
print(first) # foo
print(names) # ['bar', 'baz', 'moo']