Join our newsletter for the latest updates.

Python Program to Check if a Key is Already Present in a Dictionary

In this example, you will learn to check if a key is present in a dictionary.

To understand this example, you should have the knowledge of the following Python programming topics:

Using in keyword

my_dict = {1: 'a', 2: 'b', 3: 'c'}

if 2 in my_dict:



Keyword in can be used to check the presence of a key in a dictionary. You can use not in if you want to check if a key is not present in the dictionary.

Did you find this article helpful?