If you build anything that stores data in bulk, sooner or later you need to check if an array is empty in Python before you act on it. I ran into this exact problem last month while cleaning up a small leave-request app I built for my team here in Austin, Texas. The app tracks vacation requests for a 10-person crew, and one nasty bug showed up only when a query returned zero rows. In this guide, I will walk you through practical ways to check if an array is empty in Python across the three container types you will actually meet: the built-in list, the array.array module, and the NumPy ndarray. I am running Python 3.12 on my local machine for every example below, and I will show you the exact output each time so you can compare it against your own terminal.
Before we dive in, let’s set the scene. My leave-request app is a small Flask-style script backed by sqlite3, with datetime used to stamp when a request was submitted. Every time someone on the team submits a request, it gets appended to a list in memory before being written to the database. The bug happened when the list of “pending requests for today” was empty, but my code assumed it always had at least one item. That one assumption crashed the whole approval page. Let’s fix that kind of mistake properly, one array type at a time.
Why Checking for an Empty Array Actually Matters
An “array” in casual Python conversation usually means one of three things: a plain list, an array.array (a compact, typed container from the standard library), or a NumPy ndarray (the workhorse of numeric computing). They look similar on the surface, but they behave differently when you ask “is this empty?” That difference is exactly where beginners get tripped up.
In my leave-request app, I use all three at different points:
- A plain Python
listholds the raw leave requests pulled fromsqlite3for the day. - An
array.arraystores the numeric employee IDs of everyone who is currently on leave, because I only need integers and want a smaller memory footprint. - A NumPy
ndarrayholds a full month’s worth of daily headcount numbers so I can quickly compute averages and spot short-staffed days.
If you skip the empty check, you will eventually hit an IndexError, a confusing calculation, or worse, silent wrong output. Let’s look at each container type in turn.
How to Check If an Array Is Empty in Python for a List
The plain list is the most common array-like structure in Python, and it is also the easiest one to check. Python treats an empty list as “falsy,” meaning it behaves like False in a boolean context. That gives you the cleanest, most Pythonic check available.
Here is the pending-leave-requests list from my app on a quiet Tuesday when nobody asked for time off:
pending_requests = []
if not pending_requests:
print("No leave requests pending today.")
else:
print(f"{len(pending_requests)} request(s) waiting for approval.")Output:
No leave requests pending today.You can refer to the screenshot below to see the output.

The not pending_requests check works because Python evaluates an empty list as False and a non-empty list as True, regardless of what is inside it. You do not need to know the length in advance; you just ask “is there anything here at all?”
Now compare that to a day when two of my team members, Sarah and Marcus, both submit requests:
pending_requests = ["Sarah - Aug 4-8", "Marcus - Aug 11"]
if not pending_requests:
print("No leave requests pending today.")
else:
print(f"{len(pending_requests)} request(s) waiting for approval.")Output:
2 request(s) waiting for approval.You can also use len(pending_requests) == 0 if you want to be explicit, which some teams prefer for readability in code reviews:
pending_requests = []
print(len(pending_requests) == 0)Output:
TrueBoth approaches are correct for a plain list. I lean toward not pending_requests in my own scripts because it reads closer to plain English, but len(...) == 0 is perfectly fine and arguably clearer to someone new to the codebase. If you want a deeper look at counting items in a sequence, this guide on checking the length of an array in Python covers more edge cases. And if you are still getting comfortable creating these structures in the first place, start with this walkthrough on creating arrays in Python.
One trap to avoid: do not confuse “empty” with “None.” A list that has not been created yet is None, not an empty list, and not None also evaluates to True, which can mask a bug where you forgot to initialize the list at all. If that distinction feels fuzzy, this comparison of is None versus None in Python explains the difference plainly. In my leave app, I explicitly initialize pending_requests = [] at the top of the day’s processing function so I never accidentally check emptiness on a None value.
Checking If an array.array Is Empty
The array.array type from the standard library is less commonly used than list, but it shows up when you need a compact, single-type numeric container. In my leave-request app, I use it to store the employee IDs of everyone currently marked “on leave,” since IDs are always plain integers and I do not need the overhead of a general-purpose list.
The good news: array.array is checked for emptiness the exact same way as a plain list, because it also supports truthy/falsy evaluation and len().
from array import array
on_leave_ids = array("i", [])
if not on_leave_ids:
print("Nobody is on leave this week.")
else:
print(f"{len(on_leave_ids)} employee(s) currently on leave.")Output:
Nobody is on leave this week.You can refer to the screenshot below to see the output.

Now let’s say three people on the 10-person team, employee IDs 4, 7, and 9, are on leave this week:
from array import array
on_leave_ids = array("i", [4, 7, 9])
if not on_leave_ids:
print("Nobody is on leave this week.")
else:
print(f"{len(on_leave_ids)} employee(s) currently on leave.")Output:
3 employee(s) currently on leave.The "i" you see in array("i", [...]) is a type code telling Python this array only holds signed integers. That is the main practical difference between array.array and list: an array.array enforces one data type for everything it holds, which keeps memory usage down when you have a lot of numbers. If you are unsure whether a list, tuple, or array.array is the right fit for a given job, this rundown of lists, tuples, sets, and dictionaries in Python lays out the tradeoffs clearly.
Pro Tip: I always run a quick
type()check when I am debugging an “empty array” bug in a hurry, because I have personally lost twenty minutes assuming I had a NumPy array when it was actually a plain list someone else on my team had passed in. A one-lineprint(type(my_array))before your empty check saves you from chasing the wrong solution.
How to Check If an Array Is Empty in Python with NumPy
This is where things get genuinely different, and where most beginners get burned. A NumPy ndarray does not support the simple if not my_array: trick once it has more than one element, because NumPy tries to evaluate truthiness element-by-element and raises a ValueError when the array has multiple values. This is one of the most common early-career NumPy errors, and it deserves its own explanation.
Let’s use my monthly headcount tracker as the example. It holds the number of people who showed up to work each day this month, pulled from the sqlite3 database and stamped with datetime for the date range.
import numpy as np
daily_headcount = np.array([])
if daily_headcount.size == 0:
print("No headcount data recorded yet.")
else:
print(f"Average headcount: {daily_headcount.mean():.1f}")Output:
No headcount data recorded yet.You can refer to the screenshot below to see the output.

The .size attribute tells you the total number of elements in the array, and comparing it to 0 is the standard, reliable way to check if a NumPy array is empty. It works no matter how many dimensions the array has, which matters once your data has more shape to it than a flat list.
Now here is the classic mistake. If you try the list-style trick on a NumPy array with more than one value, Python throws an error instead of giving you a clean answer:
import numpy as np
daily_headcount = np.array([8, 9, 7, 10])
if not daily_headcount:
print("No headcount data recorded yet.")Output:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()That error is NumPy’s way of saying “I don’t know if you mean ‘any element is nonzero’ or ‘all elements are nonzero,’ so I refuse to guess.” Sticking with .size == 0 avoids this entirely, because size is just a plain integer count with no ambiguity.
Here’s the correct version running against real data, four days of headcount for the team:
import numpy as np
daily_headcount = np.array([8, 9, 7, 10])
if daily_headcount.size == 0:
print("No headcount data recorded yet.")
else:
print(f"Average headcount: {daily_headcount.mean():.1f}")Output:
Average headcount: 8.5This same .size approach holds up for multi-dimensional arrays too, which is common once your leave-tracking data grows into a grid, say, rows for each employee and columns for each week of the quarter.
import numpy as np
quarterly_grid = np.empty((0, 4))
print(quarterly_grid.size)
print(quarterly_grid.shape)Output:
0
(0, 4)Notice that .shape still reports (0, 4), meaning “zero rows, four columns,” even though the array is empty. That is a subtle but important point: a NumPy array can have a defined shape and still hold zero actual data, which is different from a plain list that simply has no length at all. If shapes are new territory for you, this explainer on NumPy shape breaks it down clearly, and the broader introduction to Python NumPy arrays is a solid starting point if you are newer to the library overall. For a dedicated, deeper walkthrough specifically on this exact emptiness question, see this guide on checking if a NumPy array is empty.
Things to Keep in Mind
- not my_array only works safely on plain lists and array.array, not multi-element NumPy arrays. Using it on NumPy data with more than one value throws a
ValueErrorinstead of the answer you want. - .size is your go-to attribute for NumPy emptiness checks. It counts every element across all dimensions, so it works whether your data is flat or shaped like a grid.
- An empty list and a None value are not the same thing. Always initialize your containers explicitly so an “empty” check never accidentally runs against nothing at all.
- array.array requires a single, consistent data type. If you are mixing strings and numbers, you need a plain list instead, since
array.arraywill raise aTypeErroron creation. - len() works consistently across lists and array.array, but .size is more reliable for NumPy. Mixing up which method belongs to which container is the single most common source of confusion here.
- Test your empty-check logic with both an empty and a populated example before shipping. A check that only gets tested against non-empty data can hide bugs that only appear on quiet days, exactly like my leave-request app did.
Frequently Asked Questions
What is the fastest way to check if a Python list is empty?
Use if not my_list:. It relies on Python’s built-in truthy/falsy evaluation, so it does not need to calculate a length first, and it reads naturally in an if statement.
Why does if not my_array: fail on NumPy arrays?
NumPy raises a ValueError when an array has more than one element because it cannot decide whether you mean “any value is truthy” or “every value is truthy.” Use .size == 0 instead to sidestep the ambiguity completely.
Does array.array behave like a list or like NumPy for empty checks?
It behaves like a list. Both not my_array and len(my_array) == 0 work fine on array.array because it does not have NumPy’s element-wise truthiness rules.
Is checking len(my_array) == 0 slower than not my_array?
The difference is too small to matter in nearly all real programs, including a small team app like the leave tracker in this guide. Pick whichever reads more clearly to your team and stay consistent.
How do I check if a multi-dimensional NumPy array is empty?
Check my_array.size == 0. It counts every element across every dimension, so a shape like (0, 4) correctly reports a size of zero even though the shape itself is not empty.
Can an empty array still have a defined shape in NumPy?
Yes. A NumPy array created with something like np.empty((0, 4)) has zero elements but still reports a shape of (0, 4), meaning it remembers the column count even with no rows of data.
This guide covered how to check if an array is empty in Python across a plain list, an array.array, and a NumPy ndarray, with the exact output for each approach. The safest habit across all three is to know which container you are holding, then reach for not my_array or len() == 0 on lists and array.array, and .size == 0 on NumPy. I hope you found this article helpful.
You May Also Like
- How to Initialize an Array in Python
- How to Create a 2D Array in Python
- How to Convert a List to an Array in Python
- How to Remove Elements From an Array in Python
- How to Find the Index of an Element in an Array in Python

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.