Write a python program to check if a given key exists in a dictionary or not.

 # Sample dictionary

my_dict = {

    "name": "Rahul",

    "age": 25,

    "city": "Mumbai"

}


# Key to check

key_to_check = "age"


# Check if key exists

if key_to_check in my_dict:

    print(f"Key '{key_to_check}' exists in the dictionary.")

else:

    print(f"Key '{key_to_check}' does not exist in the dictionary.")

Output:


Comments