PyPython example

How to check if a list is empty in Python

4 min read▶ Runs in an isolated hosted runtimeUpdated Jul 2026

Quick answer

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.

empty_check.py

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.

len_check.py

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.

equality.py

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.

none_vs_empty.py

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?

MethodReadabilityAny sequencePEP 8 says
if not items:GreatYesPreferred
len(items) == 0ExplicitYesNot preferred
items == []NarrowNo — lists onlyDiscouraged
items is NoneGreatIdentity, not lengthPreferred 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.

nested.py

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 Falseis 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.