To remove the first element from a list in Python, use my_list.pop(0). It deletes the element at index 0 and returns it. If you don’t need the value, del my_list[0] does the same without returning anything, and my_list[1:] gives you a new list without the first element while leaving the original alone.
fruits = ["apple", "banana", "cherry", "date"]
first = fruits.pop(0) # remove the first element and return it
print(first)
print(fruits)
Output:
apple
['banana', 'cherry', 'date']
pop(0) run in the Windows Command Prompt.Every example was run with Python 3.12.5 and NumPy 2.5.3; the output shown is from those runs.
Method 1: pop(0)
pop(0) (see More on Lists in the Python tutorial) is the answer when you want to use the removed element, for example to process items in the order they arrived. Note the 0: without an index, pop() removes the last element:
fruits = ["apple", "banana", "cherry"]
print(fruits.pop()) # no index: removes the LAST element
print(fruits)
Output:
cherry
['apple', 'banana']
Method 2: del list[0]
fruits = ["apple", "banana", "cherry", "date"]
del fruits[0] # remove it, don't keep it
print(fruits)
Output:
['banana', 'cherry', 'date']
Method 3: slicing (list without the first element)
fruits = ["apple", "banana", "cherry", "date"]
rest = fruits[1:] # a NEW list without the first element
print("rest: ", rest)
print("fruits:", fruits) # the original is unchanged
Output:
rest: ['banana', 'cherry', 'date']
fruits: ['apple', 'banana', 'cherry', 'date']
Slicing never changes the original list, which is what you want when other code still uses it.
Unpacking: first element and the rest
fruits = ["apple", "banana", "cherry", "date"]
first, *rest = fruits # split into the first element and the rest
print(first, rest)
Output:
apple ['banana', 'cherry', 'date']
Which method should you use?
original = ["a", "b", "c", "d"]
data = original.copy(); x = data.pop(0)
print("pop(0): ", data, "| returned", repr(x), "| list changed:", data != original)
data = original.copy(); del data[0]
print("del data[0]: ", data, "| returned nothing | list changed:", data != original)
data = original.copy(); rest = data[1:]
print("data[1:]: ", rest, "| list changed:", data != original)
data = original.copy(); first, *rest = data
print("first, *rest:", rest, "| first =", repr(first), "| list changed:", data != original)
Output:
pop(0): ['b', 'c', 'd'] | returned 'a' | list changed: True
del data[0]: ['b', 'c', 'd'] | returned nothing | list changed: True
data[1:]: ['b', 'c', 'd'] | list changed: False
first, *rest: ['b', 'c', 'd'] | first = 'a' | list changed: False
And with an empty list:
empty = []
print("empty[1:] ->", empty[1:])
try:
first, *rest = empty
except ValueError as err:
print("first, *rest = [] ->", err)
try:
del empty[0]
except IndexError as err:
print("del empty[0] ->", err)
Output:
empty[1:] -> []
first, *rest = [] -> not enough values to unpack (expected at least 1, got 0)
del empty[0] -> list assignment index out of range
| Method | Changes the list? | Returns the element? | Empty list |
|---|---|---|---|
l.pop(0) | Yes | Yes | IndexError |
del l[0] | Yes | No | IndexError |
l[1:] | No (new list) | No | Returns [] |
first, *rest = l | No (new list) | Yes | ValueError |
deque.popleft() | Yes | Yes | IndexError |
Remove the first N elements
numbers = [10, 20, 30, 40, 50, 60]
print(numbers[3:]) # new list without the first 3
del numbers[:3] # remove the first 3 in place
print(numbers)
Output:
[40, 50, 60]
[40, 50, 60]
Remove the first occurrence of a value
If “first element” means the first element equal to something, use remove():
colors = ["red", "blue", "red", "green"]
colors.remove("red") # removes the FIRST "red" only
print(colors)
Output:
['blue', 'red', 'green']
Removing from an empty list
items = []
items.pop(0)
Output:
IndexError: pop from empty list
Check the list first, or wrap it in a helper:
def pop_first(items, default=None):
return items.pop(0) if items else default
queue = ["job1"]
print(pop_first(queue), pop_first(queue), queue)
Output:
job1 None []
Remove from the front many times: use deque
A list stores its items next to each other, so pop(0) has to shift every remaining item one place to the left. That’s instant for small lists but gets slow when you remove from the front of a long list over and over, as in a queue. collections.deque is built for this: popleft() takes the same time no matter how long the deque is.
from collections import deque
tasks = deque(["write", "test", "deploy"])
print(tasks.popleft()) # remove from the front in constant time
print(tasks)
tasks.append("monitor")
print(list(tasks))
Output:
write
deque(['test', 'deploy'])
['test', 'deploy', 'monitor']
import timeit
setup = "from collections import deque; data = list(range(50_000))"
tests = {
"list.pop(0) until empty": "l = data.copy()\nwhile l: l.pop(0)",
"deque.popleft() until empty": "d = deque(data)\nwhile d: d.popleft()",
"list.pop() (from the end)": "l = data.copy()\nwhile l: l.pop()",
}
for name, stmt in tests.items():
t = min(timeit.repeat(stmt, setup=setup, number=1, repeat=3))
print(f"{name:28} {t * 1000:8.1f} ms")
Output (removing 50,000 items one by one):
list.pop(0) until empty 2483.7 ms
deque.popleft() until empty 1.1 ms
list.pop() (from the end) 1.2 ms
pop(0) vs deque.popleft().On this run, emptying the list with pop(0) took 2,484 ms, while popleft() took 1.1 ms. For a handful of items the difference doesn’t matter; for a queue, use a deque.
Don’t remove items while looping over the same list
numbers = [1, 2, 3, 4, 5]
for n in numbers: # removing while iterating skips items
numbers.pop(0)
print(numbers)
Output:
[4, 5]
The for loop moves forward while the list shrinks from the front, so the loop stops early and items are left over. Use a while loop instead:
numbers = [1, 2, 3, 4, 5]
while numbers: # safe: check the list each time
print("processing", numbers.pop(0))
print(numbers)
Output:
processing 1
processing 2
processing 3
processing 4
processing 5
[]
Remove the first element from a NumPy array
NumPy arrays have a fixed size, so there is no pop(). Slice or use np.delete(), which both give you a new array (or view):
import numpy as np
arr = np.array([10, 20, 30, 40])
print(arr[1:]) # view without the first element
print(np.delete(arr, 0)) # new array without index 0
print(arr) # NumPy arrays can't shrink in place
Output:
[20 30 40]
[20 30 40]
[10 20 30 40]
np.delete() leave the original array unchanged.import numpy as np
arr = np.array([10, 20, 30])
arr.pop(0)
Trying pop() on an array:
AttributeError: 'numpy.ndarray' object has no attribute 'pop'
The standard-library array module, on the other hand, supports pop(0) like a list:
from array import array
a = array("i", [10, 20, 30])
print(a.pop(0), a)
Output:
10 array('i', [20, 30])
Sets, strings and dictionaries
A set has no order, so it has no first element: pop() removes an arbitrary one.
s = {"banana", "apple", "cherry"}
print(s.pop()) # removes an ARBITRARY element: sets have no first element
Output:
banana
A string can’t be changed; slice it to get a new string (remove the first character from a string):
text = "Python"
print(text[1:]) # strings can't be changed: build a new one without the first character
Output:
ython
A dictionary keeps insertion order, so its first key is next(iter(d)):
d = {"a": 1, "b": 2, "c": 3}
first_key = next(iter(d)) # dicts keep insertion order (Python 3.7+)
print(first_key, d.pop(first_key), d)
Output:
a 1 {'b': 2, 'c': 3}
Get the first element without removing it
fruits = ["apple", "banana"]
print(fruits[0], fruits) # read the first element without removing it
Output:
apple ['apple', 'banana']
You might also like these list tutorials:
- Remove the last element from a list
- Remove an element from a list by index
- Remove an element from a list in Python
- Remove the first character from a string
Frequently asked questions
How do I remove the first element from a list in Python?
my_list.pop(0) removes and returns it; del my_list[0] removes it without returning it.
Does pop() remove the first element?
No. pop() without an argument removes the last element. Use pop(0) for the first.
How do I get a list without the first element?
my_list[1:] returns a new list without the first element and leaves the original unchanged.
How do I remove the first N elements?
del my_list[:n] in place, or my_list[n:] for a new list.
Is list.pop(0) slow?
It shifts every remaining item, so repeatedly removing from the front of a long list is slow. Use collections.deque and popleft() for queues.
How do I remove the first element from a NumPy array?
arr[1:] or np.delete(arr, 0). NumPy arrays have no pop() method.
Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn