In this example we will show how to determine if a specified key is present in a dictionary in Python.
Source Code
mydict = {
'name': 'Steven',
'age': 24,
'ID': 123456
}
if 'name' in mydict:
print("'name' is one of the keys in the thisdict dictionary.")
else:
print("'name' is not one of the keys in the thisdict dictionary.")
Output:
'name' is one of the keys in the thisdict dictionary.