How to check if a value exists in a dictionary (python)
Now we will see the example to check key and value exists in the dictionary or not.
Example: 1
user_info = {'name': 'Pramod', 'Rollno': '17691a05b9', 'Branch': 'CSE'} if 'name' in user_info: print("prensent") else: print("not present")
Output:
C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C: / Users / Pramod / PycharmProjects / pythonProject / main.py prensent Process finished with exit code 0
Example: 2
if 22 in user_info.values(): print('exis') else: print('not exist')
Output:
C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py not exist Process finished with exit code 0
Recommended Post:
- Python Hello World Program
- Python Comment | Creating a Comment | multiline comment | example
- Python Dictionary Introduction | Why to use dictionary | with example
- How to do Sum or Addition in python
- Python Reverse number
- find the common number in python
- addition of number using for loop and providing user input data in python
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if the condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data, POP, pop item, update method
- Python Dictionary | update() method
- Delete statement, Looping in the list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
Get Salesforce Answers