Use the list's own truthiness: if not items:. An empty list is falsy, so the branch runs for [] and is skipped for a list with anything in it — and it's the form PEP 8 recommends.
Every empty built-in container in Python is falsy — [], (), "", {} — so you rarely need to measure a list to find out whether it has anything in it. The one thing to watch for is that None is falsy too, so a bare not items can't tell "empty list" apart from "no list at all". Each example below runs on this page.
1The truthiness checkRecommended
An empty list is falsy and a populated one is truthy, so if not items: reads as "if there's nothing here" with no function call and no comparison.
items = [] if not items: print("The list is empty") else: print(f"The list has {len(items)} item(s)") items.append("compile") if not items: print("The list is empty") else: print(f"The list has {len(items)} item(s)")
Output
Prints The list is empty then The list has 1 item(s). PEP 8 spells this out: for sequences, use the fact that an empty sequence is false rather than comparing a length. It also works unchanged on tuples, strings, sets and dicts.
2len(items) == 0
Comparing the length is more verbose but perfectly correct, and it's the clearer choice when zero isn't the only size you care about — batching, pagination, and "at least N" guards all read better as explicit numbers.
items = [] print(len(items) == 0) # len() earns its keep when zero is not the only threshold you care about batch = [1, 2, 3] if len(batch) == 0: print("nothing to send") elif len(batch) < 5: print(f"holding {len(batch)} items - waiting for a full batch of 5") else: print("sending")
Output
Prints True then holding 3 items - waiting for a full batch of 5. Note that len() raises TypeError on None, while not None quietly evaluates to True — that difference matters in the next section.
3items == [] (and why to avoid it)
Comparing against an empty list literal works for lists, but it's the narrowest of the three: it builds a throwaway list on every check and it is False for every other kind of empty container. Swap a list for a tuple or a deque later and the check silently stops firing.
from collections import deque print([] == []) # but == [] only matches an empty list - nothing else for value in ((), deque(), "", {}): name = type(value).__name__ print(f"{name:<5} value == [] -> {str(value == []):<5} not value -> {not value}")
Output
The empty tuple, deque, string and dict all report value == [] -> False while not value -> True. That's the whole argument against == []: truthiness describes emptiness, equality describes type and contents.
4Empty list vs None
None and [] are both falsy, so not items can't separate "the caller passed an empty list" from "the caller passed nothing". Test the identity first with if items is None:, then fall through to the truthiness check. This also fixes the classic mutable default argument bug: a def f(items=[]) default is created once, at definition time, and every call that omits the argument shares that same list.
def add_tag(tag, tags=[]): # trap: the default list is created ONCE tags.append(tag) return tags print(add_tag("python")) print(add_tag("lists")) # the earlier tag is still in there def add_tag_safe(tag, tags=None): # None means "nothing was passed" if tags is None: tags = [] elif not tags: print("(got an empty list)") tags.append(tag) return tags print(add_tag_safe("python")) print(add_tag_safe("lists", [])) print(bool(None), bool([]), None == [])
Output
The buggy version prints ['python'] then ['python', 'lists'] — the leak. The safe version prints ['python'] and ['lists'], and reports (got an empty list) only for the call that really passed []. The last line is False False False: both values are falsy, yet None == [] is False — they are genuinely different things.
5Which should you use?
| Method | Readability | Any sequence | PEP 8 says |
|---|---|---|---|
| if not items: | Great | Yes | Preferred |
| len(items) == 0 | Explicit | Yes | Not preferred |
| items == [] | Narrow | No — lists only | Discouraged |
| items is None | Great | Identity, not length | Preferred for None |
6Common variation: empty rows in a list of lists
A list of lists is never empty just because its rows are. Filter the empty rows out with the same truthiness test inside a comprehension, and use all() / any() to ask about the grid as a whole.
rows = [[1, 2], [], [3], [], []] non_empty = [row for row in rows if row] print(non_empty) print(f"dropped {len(rows) - len(non_empty)} empty rows") grid = [[], [], []] print(all(not row for row in grid)) # every row empty? print(any(grid)) # any row with something in it?
Output
Output: [[1, 2], [3]], dropped 3 empty rows, then True and False. any(grid) is the shortest way to ask "is there any content anywhere in here" — it stops at the first truthy row.
Frequently asked questions
What is the most Pythonic way to check if a list is empty?
if not items: — PEP 8 recommends using the fact that an empty sequence is falsy instead of comparing a length. For a real list it always agrees with len(items) == 0; the two diverge only when the value might be None, since not None is True but len(None) raises a TypeError.
How do I tell an empty list from None in Python?
Check if items is None: first, then fall through to if not items:. Both None and [] are falsy so a bare not items cannot separate them, and None == [] is False — is is the correct comparison for singletons like None.
Why is def f(items=[]) a bug?
The default list is created once, when the function is defined, and every call that omits the argument shares it — so appends leak from one call into the next. Use items=None as the default and build a fresh [] inside the function when items is None.
Why should I avoid items == [] to check for an empty list?
It only matches an empty list. An empty tuple, set, string, dict or deque is never equal to [], so the check silently returns False for them, and it constructs a throwaway empty list on every comparison. if not items: covers every empty sequence.
Run it yourself
Open any of these in the full Python editor — tweak, run, and share.
Python playground