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

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

Answer from Patrick on Stack Overflow
๐ŸŒ
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.
Discussions

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 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
BeautifulSoup returns empty list

Do u just want the titles? If so gimme a sec :)

Edit: First things first, 'qs-rankings' is an id not a class & it doesn't look like the request is retrieving the table with universities in it (this is probs because they're loaded via javascript when the page is loaded and the requests library can't execute this, if u look at view page source and do ctrl+f to find the first entry in the table, you'll see this is true). There could be a bypass so just gimme a couple minute :)

More on reddit.com
๐ŸŒ r/learnpython
11
3
July 27, 2017
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
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
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
๐ŸŒ
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...
๐ŸŒ
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()

--

๐ŸŒ
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 Guides
pythonguides.com โ€บ check-if-numpy-array-is-empty
Check If NumPy Array Is Empty In Python
May 6, 2025 - Check if a NumPy array is empty with arr.size == 0. See why len() and if not arr fail, why np.isempty doesn't exist, and how to check lists.
Find elsewhere
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ numpy โ€บ python-numpy-exercise-95.php
NumPy: Check whether the numpy array is empty or not - w3resource
August 29, 2025 - Write a NumPy program to check whether the NumPy array is empty or not. Pictorial Presentation: Sample Solution: Python Code: # Importing the NumPy library and aliasing it as 'np' import numpy as np # Creating a NumPy array 'x' containing integers [2, 3] x = np.array([2, 3]) # Creating an empty NumPy array 'y' y = np.array([]) # Printing the size of array 'x' # As 'x' contains 2 elements, its size is 2 print(x.size) # Printing the size of array 'y' # 'y' is an empty array, so its size is 0 print(y.size) Sample Output: 2 0 ยท
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Curict
en.curict.com โ€บ item โ€บ 9a โ€บ 9a5983d.html
Checking if a Python list is empty - curict.com
Since None is also considered False, if you want to strictly compare None and an empty list, you can use the โ€œis Noneโ€ operator to check. ... # Checking for an empty list considering None if emptyList is None: print('It is None') elif not emptyList: print('The list is empty')
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Appdividend
appdividend.com โ€บ create-and-check-if-a-numpy-array-is-empty
How to Create and Check If a Numpy Array is Empty
July 10, 2025 - The easiest and most robust way to check if a numpy 1d, 2d, 3d, or multi-dimensional array is empty using np.ndarray.size attribute.
๐ŸŒ
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, ... array.size == 0: print('Empty list') else: print('List is not empty') Empty list ยท The not operator is the most Pythonic and efficient way to check for empty lists....
๐ŸŒ
Vultr
docs.vultr.com โ€บ python โ€บ examples โ€บ check if a list is empty
Python Program to Check If a List is Empty
December 6, 2024 - Compare the list directly to an empty list [] using the == operator. This method makes the check explicit and clear in the code.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-check-if-a-list-is-empty-in-python
Python isEmpty() equivalent โ€“ How to Check if a List is Empty in Python
April 19, 2023 - In the code above, we used an if statement and the not operator to check if the people_list was empty. You can use the len() function in Python to return the number of elements in a data structure.