How do I check if a list is empty?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
In Python, you can check if a list is empty in several ways. Here are the most common and Pythonic methods:
1. Using if not list (Recommended)
The most Pythonic way to check if a list is empty is to take advantage of its "truthy" or "falsy" value.
Example:
Why it Works:
- An empty list evaluates to
Falsein a conditional statement. - A non-empty list evaluates to
True.
2. Using len()
You can check the length of the list with the len() function.
Example:
Explanation:
len(my_list)returns0if the list is empty.
3. Using == []
You can directly compare the list to an empty list [].
Example:
Note:
While this works, it is less Pythonic than using if not list.
4. Using any() (For Non-Empty Values)
If you want to check if a list has any non-empty values, use any().
Example:
Explanation:
any()checks if at least one element is truthy.
5. Checking Directly with bool()
You can explicitly convert the list to a boolean using bool().
Example:
Explanation:
bool([])evaluates toFalsefor an empty list.bool([1, 2, 3])evaluates toTruefor a non-empty list.
Comparison of Methods
| Method | Description | Pythonic |
if not list | Checks if the list evaluates to False | ✅ Yes |
len(list) == 0 | Checks length of the list | ⚠️ Less Pythonic |
list == [] | Compares list directly to [] | ⚠️ Less Pythonic |
bool(list) | Explicitly converts list to a boolean | ✅ Yes |
any(list) | Checks for any truthy elements | ✅ Depends on case |
Recommended Way
The most Pythonic and efficient method to check if a list is empty is:
This method is clean, concise, and widely adopted in Python code. 🚀
Related reading
- How do I check if an array includes a value in JavaScript?
- How do I concatenate two lists in Python?
- How do I list all files of a directory?
- How do I make a flat list out of a list of lists?
- How do I clone a list so that it doesn't change unexpectedly after assignment?
- How do I put a time delay in a Python script?
- How do I sort a dictionary by value?
- How do I split a list into equally-sized chunks?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.