Check if Key Exists in Dictionary Python Using Get()

(Last Updated On: 07/02/2023)

Python Program to Check if Key Exists in Dictionary Using Get()

# Check if a Key is Already Present in a Dictionary Python using get()

dic = {'a': 100, 'b':200, 'c':300}

# check if "b" is none or not.
if dic.get('b') == None:
    print("Not Present")
else:
    print("Present")

Output:

Present

Leave a Reply

Your email address will not be published. Required fields are marked *