Python 3 Code to Check Whether a Key Exists in a Dictionary

0Shares

main.py

d = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
def is_key_present(x):
  if x in d:
      print('Key is present in the dictionary')
  else:
      print('Key is not present in the dictionary')
is_key_present(5)
is_key_present(9)
0Shares

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.