How to Check if a Dictionary is Empty in Python?

Sometimes, I needed to validate API responses as a part of my project. Other times, I had to make sure a configuration dictionary wasn’t missing required values.

At first, I thought there was only one way to do this. But as I gained more experience, I discovered multiple approaches, each useful in different scenarios.

In this tutorial, I’ll share four practical methods I use to check if a dictionary is empty in Python. I’ll also explain when you should use each one.

Method 1 – Use the not Operator

The simplest and most efficient way to check if a Python dictionary is empty is by using the not operator.

# Example: Using 'not' to check if dictionary is empty

user_data = {}

if not user_data:
    print("The dictionary is empty.")
else:
    print("The dictionary has data.")

You can see the output in the screenshot below.

python empty dictionary

Here, not user_data evaluates to True if the dictionary is empty. This works because empty dictionaries are considered False in Python.

I use this method most often because it’s short, clean, and easy to read.

Method 2 – Use the len() Function

Another common way is to check the length of the dictionary in Python.

# Example: Using len() to check if dictionary is empty

order_details = {}

if len(order_details) == 0:
    print("The dictionary is empty.")
else:
    print("The dictionary has data.")

You can see the output in the screenshot below.

empty dictionary python

The len() function returns the number of key-value pairs in the dictionary. If it equals 0, the dictionary is empty.

This method is very clear for beginners, as it directly shows what we are checking.

Method 3 – Use the bool() Function

You can also use the Python’s bool() function to convert the dictionary into a Boolean.

# Example: Using bool() to check if dictionary is empty

config = {}

if bool(config):
    print("The dictionary has data.")
else:
    print("The dictionary is empty.")

You can see the output in the screenshot below.

python check if dict is empty

When a dictionary is empty, bool(config) returns False. When it has data, it returns True.

This method is useful when you want to explicitly convert the dictionary into a Boolean before making decisions.

Method 4 – Use Equality Operator == {}

Finally, you can compare the dictionary directly with an empty dictionary {} in Python.

# Example: Comparing dictionary with {}

student_scores = {}

if student_scores == {}:
    print("The dictionary is empty.")
else:
    print("The dictionary has data.")

This method is very simple. You’re asking, “Is this dictionary equal to an empty one?”

I don’t use this method often, but it’s still a valid option when you want to be very explicit.

Which Method Should You Use?

  • If you want the most Pythonic way → use not dict.
  • If you want something beginner-friendly → use len(dict) == 0.
  • If you want to explicitly check Boolean values → use bool(dict).
  • If you want a clear comparison → use dict == {}.

Personally, I recommend using the not operator because it’s concise and widely accepted in the Python community.

Checking if a dictionary is empty may sound simple, but as you’ve seen, there are multiple ways to do it. In my projects, I usually stick with the not operator because it’s clean and efficient. But depending on the situation, the other methods can be just as useful.

I hope you found this tutorial helpful. Try out each method in your projects, and you’ll quickly see which one feels most natural.

You may like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.