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 - The not operator is the simplest way to see if a list is empty. It returns True if the list is empty and False if it has any items.
๐ŸŒ
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()

--

๐ŸŒ
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.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ check if a string is empty in python
Python Truth Value Testing for Empty String Checks | Sentry
Check if a Python string is empty using truth value testing with the not operator, strict comparison with == "", or strip() to handle whitespace-only strings
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.empty.html
numpy.empty โ€” NumPy v2.6.dev0 Manual
>>> import numpy as np >>> np.empty([2, 2]) array([[ -9.74499359e+001, 6.69583040e-309], [ 2.13182611e-314, 3.06959433e-309]]) #uninitialized
๐ŸŒ
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 __nonzero__ is the interface for testing emptiness (__bool__ in python 3 โ†’ built-in bool())
Find elsewhere
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ define-empty-variables-python
How to Define Empty Variables and Data Structures in Python | Built In
An empty variable in Python is a variable with no assigned value, often used as a placeholder in the code for a missing value. Empty variables can be defined using the None keyword (like a = None) or by leaving syntax as empty (like a_list = []).
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ checking-for-an-empty-list-in-python
Checking for an empty list in Python - Python Morsels
July 18, 2026 - Python programmers typically check for empty lists by relying on truthiness.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-purpose-of-an-empty-statement-in-Python
What is the purpose of an empty statement in Python? - Quora
Answer: There is nothing called โ€œempty statementโ€ in Python, so I assume youโ€™re asking about one of two things: a blank line (possibly with an indent to the current indentation level, possibly with a comment, but nothing else on it), or a pass statement.
๐ŸŒ
Better Stack
betterstack.com โ€บ community โ€บ questions โ€บ how-to-check-if-list-is-empty-in-python
How do I check if a list is empty in Python? | Better Stack Community
January 26, 2023 - There are two ways you can get the current time in python. using the datetime object using the time module Using the datetime object First, you need to import the datetime module.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.empty.html
numpy.empty โ€” NumPy v2.2 Manual
>>> np.empty([2, 2], dtype=int) array([[-1073741821, -1067949133], [ 496041986, 19249760]]) #uninitialized
Top answer
1 of 4
4

In shell languages of the Bourne family, the : command, which does nothing at all, is typically used in two situations:

  • Placeholder for when something expects a mandatory command, e.g.

    while some_condtion
    do :
    done
    

    since do requires at least one command.

  • Discarding the arguments, but performing side effects inside the argument list, e.g.

    : ${myvar=foo}
    

I'm sure there are probably other applications that shell experts would know :)

In Python (and other languages) it's used less frequently. It can act as an argument to a higher-order function when you don't actually want to do anything. For example, say you have a function that submits a form and allows an function to be called asynchronously after submission is complete:

def submit(callback=empty_func):
    ...

This way, if the callback is not provided, the submission will still go through but no further actions will be performed. If you had used None as the default value, you'd have to explicitly check whether the callback was None, adding clutter to the code.

2 of 4
0

Rufflewind did a good job covering when you might use an empty function in a completed program. In my experience, it tends to be used more often in unfinished programs, so you can plan out what you're going to write and have it still compile until you get around to actually implementing it. In other words, it's usually just a placeholder.

It's necessary in python's case because it uses indentation to mark blocks, unlike C-like languages who use braces {}. This means if you didn't have pass, the parser couldn't tell if you meant to leave it empty or if you forgot. Including pass makes the parser much simpler, and gives you a convenient word to search for when you're looking for unimplemented blocks.

๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.8 documentation
August 13, 2026 - Curly braces or the set() function can be used to create sets. Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we discuss in the next section.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.3 โ€บ reference โ€บ generated โ€บ numpy.empty.html
numpy.empty โ€” NumPy v2.3 Manual
>>> np.empty([2, 2], dtype=int) array([[-1073741821, -1067949133], [ 496041986, 19249760]]) #uninitialized
๐ŸŒ
Kodeclik
kodeclik.com โ€บ python-empty-list
Python Empty List Tutorial
October 16, 2024 - You can create a list of your toys ... lists since they are mutable. To create an empty list, all you need to do is to set it equal to โ€œ[]โ€, like so:...
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ check-if-list-is-empty-python
How to check if a list is empty in Python? - Flexiple Tutorials
In this solution, we use the len() to check if a list is empty, this function returns the length of the argument passed. And given the length of an empty list is 0 it can be used to check if a list is empty 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.