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

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

Answer from Patrick on Stack Overflow
🌐
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....
Find elsewhere
🌐
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...
🌐
Curict
en.curict.com › item › 9a › 9a5983d.html
Checking if a Python list is empty
There are several ways to check if a list contains any elements, such as using “if not”, the built-in len function, or comparing it to an empty array. In Python, an empty sequence (an empty list) is considered False, so you can use the if not operator to check if a list is empty.
🌐
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()

--

🌐
Python Guides
pythonguides.com › check-if-an-array-is-empty-in-python
How To Check If An Array Is Empty In Python?
March 19, 2025 - Learn how to check if an array is empty in Python using conditions like `if not array`, `len(array) == 0`, or `array == []`. This guide includes examples.
🌐
Python Guides
pythonguides.com › check-if-numpy-array-is-empty
Check If NumPy Array Is Empty In Python
May 16, 2025 - In this article, I’ll cover seven practical methods you can use to check if a NumPy array is empty in Python (including size-based checks, logical functions, and comparison methods).
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-95.php
NumPy: Check whether the numpy array is empty or not - w3resource
# 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)
🌐
Flexiple
flexiple.com › python › check-if-list-is-empty-python
Python isEmpty() equivalent – How to Check if a List is Empty in Python - Flexiple - Flexiple
Learn how to determine if a list is empty in Python with simple methods. Check for empty lists using built-in functions or conditional statements.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-check-if-list-empty-not
Check if a list is empty or not in Python - GeeksforGeeks
October 24, 2024 - Explanation: len(a) returns 0 for an empty list. Lists can be directly evaluated in conditions. Python considers an empty list as False.