Python Dictionary Check if Value is Empty Example

By Hardik Savani October 30, 2023 Category : Python

Hey Friends,

This article will give you an example of python dictionary check if value is empty. we will help you to give an example of how to check python dictionary key value empty or not. It's a simple example of how to check value empty or not in dictionary python. If you have a question about python check dictionary value empty then I will give a simple example with a solution.

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.

So, without further ado, let's see simple examples:

Example 1:

main.py

userDictionary = {
  "ID": 1,
  "name": "",
  "email": "hardik@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": "hardik@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.

I hope it can help you...

Tags :
Shares