How to Check if Value is Empty in Python Dictionary?

10-Feb-2023

.

Admin

How to Check if Value is Empty in Python Dictionary?

Hi Dev,

There are several ways to check python dictionary value is empty or not. i will give you simple two ways to check python dictionary key value is empty or not. so you can see the following example codes.

In this tutorial we will go over the demonstration of how to check if value is empty in python dictionary. We will use check if dictionary empty. This post will give you simple example of python check dictionary value empty. let’s discuss about how to check value empty or not in dictionary python

Example 1:


main.py

userDictionary = {

"ID": 1,

"name": "",

"email": "piyush@gmail.com"

}

# Check value is empty or not in dictionary

if userDictionary["name"]:

print("value is not empty.")

else:

print("value is empty.")

Output:

value is empty.

Example 2:

main.py

userDictionary = {

"ID": 1,

"name": "",

"email": "piyush@gmail.com"

}

# Check value is empty or not in dictionary

if userDictionary.get("name"):

print("value is not empty.")

else:

print("value is empty.")

Output:

value is empty.

#Python