Check if Key Value Pair Exists in Dictionary Python Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Python Dictionary Check if Key Exists Example
- How to Update Value in Python Dictionary?
- How to Change Value in Python Dictionary?
- Python Dictionary Remove Element by Value Example
- Python Dictionary Delete Item by Key Example
- How to Remove Element from Python Dictionary?
- How to Remove Item from Dictionary in Python?
- How to Add a Key Value Pair to Dictionary in Python?
- How to Add Element in Dictionary Python?
- How to Add Item in Dictionary Python?
- Python Create JSON File from Dict Example
- Python List Print All Elements Except Last Example
- How to Convert List into String in Python?