if not a:
    print("List is empty")

Using the implicit booleanness of the empty list is quite Pythonic.

Answer from Patrick on Stack Overflow
๐ŸŒ
Quora
quora.com โ€บ How-do-I-check-if-an-array-is-empty-in-Python
How to check if an array is empty in Python - Quora
Answer (1 of 12): I am going to assume you are talking about lists (Python does have arrays, but they are very different to lists). Three ways : 1 Test the truthiness If you know the item is a list you do : [code]if not my_list: print(โ€˜List is emptyโ€™) [/code]Empty containers (lists,sets,t...
Discussions

python - How to check if array is not empty? - Stack Overflow
How to check if the array is not empty? I did this: if not self.table[5] is None: Is this the right way? More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Check if list or array element is empty - Stack Overflow
I know how to check if a list is empty (Best way to check if a list is empty) and how to check if a numpy array is empty (How can I check whether the numpy array is empty or not?) I have an elemen... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I check if this list is "empty"?
Well there are a few ways you could deal with this. First would be to check if userInput is an empty string before converting it to a list. Another possibility would be to filter the list to remove all empty strings, eg via a list comprehension. Or you could do the filtering inside the loop you already have that converts to integers. Or, again inside that loop, you could use a counter variable to keep track of how many integers you've converted, and print an error afterwards if it's 0. And so on. The main thing here is that you should get away from thinking about how to code something, but first work out what the steps should be, and only then code it. More on reddit.com
๐ŸŒ r/learnpython
7
1
December 8, 2022
python - How can I check whether a numpy array is empty or not? - Stack Overflow
How can I check whether a numpy array is empty or not? I used the following code, but this fails if the array contains a zero. More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

Is an array of NaN values empty?
No. NaN values are elements; use isnan when the requirement is missing-value detection rather than emptiness.
๐ŸŒ
pythonpool.com
pythonpool.com โ€บ home โ€บ numpy โ€บ check if a numpy array is empty: size, shape, and safe tests
5 Ways to Check if the NumPy Array is Empty - Python Pool
Why can I not use if array?
A multi-element NumPy array has no single truth value, so Python raises an ambiguous truth-value error.
๐ŸŒ
pythonpool.com
pythonpool.com โ€บ home โ€บ numpy โ€บ check if a numpy array is empty: size, shape, and safe tests
5 Ways to Check if the NumPy Array is Empty - Python Pool
How do I check an empty dimension?
Inspect shape or size depending on whether any zero-length dimension or the total element count defines empty for the operation.
๐ŸŒ
pythonpool.com
pythonpool.com โ€บ home โ€บ numpy โ€บ check if a numpy array is empty: size, shape, and safe tests
5 Ways to Check if the NumPy Array is Empty - Python Pool
๐ŸŒ
Python Guides
pythonguides.com โ€บ check-if-an-array-is-empty-in-python
How to Check if a NumPy Array Is Empty (arr.size)
May 6, 2025 - To check if a NumPy array is empty, test arr.size == 0. size is the total number of elements, so it is 0 only when the array holds nothing, whatever its shape. Donโ€™t use if not arr: (it raises an error for arrays with more than one element), ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-check-if-list-empty-not
Check if a list is empty or not in Python - GeeksforGeeks
October 24, 2024 - We can also use len() function to see if a list is empty by checking if its length is zero. ... Explanation: len(a) returns 0 for an empty list. Lists can be directly evaluated in conditions. Python considers an empty list as False.
Find elsewhere
๐ŸŒ
Python Pool
pythonpool.com โ€บ home โ€บ numpy โ€บ check if a numpy array is empty: size, shape, and safe tests
5 Ways to Check if the NumPy Array is Empty - Python Pool
July 13, 2026 - Use array.size == 0, which checks the total number of elements across all dimensions. A multi-element NumPy array has no single truth value, so Python raises an ambiguous truth-value error. No. NaN values are elements; use isnan when the requirement is missing-value detection rather than emptiness.
๐ŸŒ
IncludeHelp
includehelp.com โ€บ python โ€บ how-to-check-whether-a-numpy-array-is-empty-or-not.aspx
How to check whether a NumPy array is empty or not?
May 26, 2023 - The numpy.any() method checks whether any array element along a given axis evaluates to True. If the given array is not empty it returns True; False, otherwise. numpy.any(a, axis=None, out=None, keepdims=<no value>, *, where=<no value>) Consider the below Python program to check NumPy array ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ what-is-the-preferred-method-to-check-for-an-empty-array-in-numpy
What is the preferred method to check for an empty array in NumPy?
March 26, 2026 - Empty array as list length: 0 Data array as list length: 3 Is empty_array empty? True ยท The preferred method to check for an empty NumPy array is array.size == 0 due to its efficiency and readability.
๐ŸŒ
Curict
en.curict.com โ€บ item โ€บ 9a โ€บ 9a5983d.html
Checking if a Python list is empty - curict.com
# Check with the len function if len(emptyList) == 0: print('The list is empty') The previous methods also consider numeric zero and an empty string as true. To prevent this, compare it to an empty list. # Compare with an empty list if emptyList == []: print('The list is empty') Python Official ...
๐ŸŒ
Data Science Parichay
datascienceparichay.com โ€บ home โ€บ blog โ€บ how to check if a numpy array is empty?
How to Check if a Numpy Array is Empty? - Data Science Parichay
November 28, 2022 - To check if a numpy array is empty, use the array's .size attribute and check if it's equal to 0 (an array's size is zero if it has no elements).
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ how to check if a python list is empty
How to Check if a Python List is Empty โ€ข datagy
August 26, 2022 - We can check if an array is empty by using its .size attribute, which returns the size of that array.
๐ŸŒ
Medium
pavolkutaj.medium.com โ€บ how-to-check-if-a-list-dict-or-set-is-empty-in-python-as-per-pep8-35d8c64d07d0
How to Check if a List, Dict or Set is Empty in Python as per PEP8 | by Pavol Z. Kutaj | Medium
September 7, 2023 - in effect, it is saying that ... ยท The canonical way of knowing if an array in C is empty is by dereferencing the first element and seeing if it is null, assuming an array that is nul-terminated....
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ checking-for-an-empty-list-in-python
Checking for an empty list in Python - Python Morsels
July 18, 2026 - What if we checked for an empty list by comparing our list to another empty list: >>> if numbers == []: ... print("The list is empty.") ... The list is empty. This does work, but it's a little bit unusual to see in Python.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-to-check-if-a-list-is-empty-in-Python
How to check if a list is empty in Python?
April 23, 2025 - When working with NumPy arrays, ... if array.size == 0: print('Empty list') else: print('List is not empty') ... The not operator is the most Pythonic and efficient way to check for empty lists....
๐ŸŒ
Built In
builtin.com โ€บ articles โ€บ python-check-if-list-is-empty
Python Check if a List Is Empty: A Guide | Built In
There are a variety of methods that can be used to check if a list is empty in Python, including the Truth Value Testing method, the len() function and the == operator. Learn more.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how do i check if this list is "empty"?
r/learnpython on Reddit: How do I check if this list is "empty"?
December 8, 2022 -

I'm completely stumped on a computer science assignment because our lecturer has given us zero information. We're supposed to have the user input a list and check if the list is in decreasing order and print a suitable message if it is. That part works fine. However, if the list is "empty" (I'll explain the quotations in a second) then it should print the list is empty.

The problem is that, according to our brief we're supposed to use .split(",") in order to allow the user to separate their numbers with commas. The problem lies in the fact that even if a user hits enter without inputting anything, the list is still '1' long with just an empty string. I've been scouring the web to find out how to check if a list is empty. But all the tutorials have so far just been in relation to actually empty lists (as in, list = []). One did use the all() function to check that all items in the list were strings, which did work and let me print that the list is empty, but broke the original function. Could someone please help me I'm tearing my hair out with this.

--

def checkOrder():

# checks, etc.

integer_list = []

listLength = len(integer_list)

increasing = 0

decreasing = 0

singleValue = 0

# Converting inputted numbers into a split list

userInput = input("Please enter your numbers seperated by a comma (,):")

inputtedStrings = userInput.split(",")

for number in inputtedStrings:

inputtedIntegers = int(number)

integer_list.append(inputtedIntegers)

# Enumerating list

for i, val in enumerate(integer_list[:-1]):

if val <= integer_list[i+1]:

increasing = 1

elif val >= integer_list[i+1]:

decreasing = 1

# Check for a single value

if len(integer_list) == 1:

singleValue = 1

if len(integer_list) == 1 and

print("The list is empty.")

if increasing == 1:

print("The numbers are in increasing order.")

elif decreasing == 1 or singleValue == 1:

print("The numbers are in decreasing order.")

checkOrder()

--