ItSolutionStuff.com

Check if Key Value Pair Exists in Dictionary Python Example

By Hardik Savani โ€ข October 30, 2023
Python

Hello,

This tutorial will provide an example of how to check if key value exists in dictionary python. Iรขโ‚ฌโ„ขm going to show you about check if key value exists in dictionary python. This post will give you a simple example of check if value exists in nested dictionary python. In this article, we will implement a python dictionary check if key value exists.

There are several ways to check key value pair is exists or not in dictionary in python. we will use items() function to check key/value pair in python dictionary.

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

Example:

main.py

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

Output:

key value pair is exists.

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

โ˜…

Python Dictionary Check if Key Exists Example

Read Now โ†’
โ˜…

How to Update Value in Python Dictionary?

Read Now โ†’
โ˜…

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 โ†’
โ˜…

Python List Print All Elements Except Last Example

Read Now โ†’
โ˜…

How to Convert List into String in Python?

Read Now โ†’