Python Empty List: How to Check It

A condition can tell you whether a Python list has items. Python conditions use an object’s truth value, and empty lists are false.

This article shows how to check whether a list is empty and how to handle None when the variable may have no list value.

TL;DR

Use if not items: to handle an empty list and if items: when it contains one or more values.

  • Use len(items) == 0 when an explicit count makes the intent clearer.
  • Check items is None separately if the variable may be None.

What Is an Empty Python List?

A Python list is an ordered collection. Use [] or list() to create an empty one.

Lists can also be built from input that may be absent. If the program converts an iterable with list(), the resulting list can then be checked before the next operation. Keep the distinction clear: an empty list is still a list object, while None means no list value was supplied.

Python conditions use an object’s truth value. Empty lists, strings, tuples, and dictionaries are false. See the Python truth value testing documentation.

For a refresher on list structure, see Python lists.

A loop can collect matching values with append or extend. The Python list documentation covers these methods.

How to Check Whether a List Is Empty

Use if not items to enter the empty branch. I ran python3.14 empty_list_demo.py, and the empty list took that branch before accepting an appended value.

The len(items) == 0 form makes the count explicit when later code needs it, such as displaying the number of pending values.

I ran python3.14 empty_list_demo.py, and the empty list took the first branch before accepting an appended value.

Step 1: Create the list and test its truth value

The example checks the empty case and then reports the populated list.

items = []

if not items:
    print("Empty list: True")
else:
    print("Empty list: False")

items.append("queued")
print(f"After append: {items}")
print(f"Length: {len(items)}")

Run it from a file with python3.14 empty_list_demo.py. This is the captured terminal transcript:

safa@askpython:~$ python3.14 empty_list_demo.py
Empty list: True
After append: ['queued']
Length: 1
Terminal output showing an empty list check and append result

The first line confirms the empty case. After append, the list contains one string and its length is one.

Step 2: Choose an explicit alternative only when useful

List equality with [] compares contents when that is the goal. It is specific to lists.

if len(items) == 0:
    handle_empty()
else:
    process(items)

A for loop runs its body zero times for an empty list, then continues after the loop. Add a separate branch when that case needs a distinct response, such as a message or fallback value.

Edge Cases: None, Falsey Items, and Loops

Guard against None before applying list operations when the input contract permits it.

CaseWhat the condition meansWhat to do
[]No items, false in a conditionUse if not items
[0] or [False]One item, the list is trueUse truthiness to test whether the list has entries
NoneNo list object was supplied, false in a conditionCheck items is None when the distinction matters

I ran python3 probe_edge_cases.py and got TypeError: object of type ‘NoneType’ has no len(). The input was None, so len() had no list length to read.

if items is None:
    print("No list was supplied")
elif not items:
    print("The list is empty")
else:
    print("The list has items")

I compared [0] with any([0]): the list had a true truth value, while any returned false. any() tests element truth, not whether the list has entries.

Conclusion

Use the emptiness test that makes your branch clear, then keep the input contract in view. If None is allowed, decide whether it means the same thing as an empty list before choosing a fallback.

For details, consult the Python truth value testing reference and PEP 8. AskPython’s guide to if, else, and elif covers the branching syntax used here.

FAQ

These short answers cover common follow-up questions about empty lists.

Does an empty list return False in Python?

An empty list is false in a Boolean context, such as an if condition, but it is not equal to the False object.

How do I create an empty list in Python?

Use [] or call list() with no argument.

Can I append to an empty list?

Yes. Call items.append(value) to add one item to the list.

Should I check a list before a for loop?

Usually no. A for loop over an empty list executes its body zero times, add a check only when you need a separate empty-case action.

Safa Mulani
Safa Mulani

An enthusiast in every forthcoming wonders!

Articles: 189