ItSolutionStuff.com

Python Dictionary Check if Value Exists Example

By Hardik Savani • October 30, 2023
Python

Hey Artisan,

This tutorial will give you an example of python dictionary check if value exists. you'll learn how to check if value is present or not in dictionary python. This tutorial will give you a simple example of python check value in dictionary exists. let us discuss about python check if values exists in dictionary. Let's get started with python dictionary value exists or not.

There are several ways to check value is exists or not in dictionary in python. i will give you two examples using if condition and using custom function in python.

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

Example 1:

main.py

user = {
  "ID": 1,
  "name": "Hardik",
  "email": "hardik@gmail.com"
}
  
# Check value is present in dictionary
if "Hardik" in user.values():
    print("value is exists.")
else:
    print("value is not exists.")

Output:

value is exists.

Example 2:

main.py

user = {
  "ID": 1,
  "name": "Hardik",
  "email": "hardik@gmail.com"
}

def checkValueExists(dic, key):
    if key in dic.values():
        print("Present")
    else:
        print("Not present")
         
# Check value is present in dictionary
value = 'Hardik'
checkValueExists(user, value)
 
# Check value is present in dictionary
value = 'w'
checkValueExists(user, value)

Output:

Present
Not present

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Change Value in Python Dictionary?

Read Now →

Python Dictionary Remove Element by Value Example

Read Now →

Python Dictionary Delete Item by Key Example

Read Now →

How to Remove Element from Python Dictionary?

Read Now →

How to Remove Item from Dictionary in Python?

Read Now →

How to Add a Key Value Pair to Dictionary in Python?

Read Now →

How to Add Element in Dictionary Python?

Read Now →

How to Add Item in Dictionary Python?

Read Now →

Python Create JSON File from Dict Example

Read Now →

How to Check If a List is Empty or Not in Python?

Read Now →

How to Add Element at Specific Index in Python List?

Read Now →

How to Get Min Value from Python List?

Read Now →

How to Convert List to Uppercase in Python?

Read Now →

How to Convert List into String in Python?

Read Now →