Write a program to check whether a given key already exists in a dictionary.


Topic: Write a program to check whether a given key already exists in a dictionary.

Solution

  
def checkKey(dict, key): 
      
    if key in dict.keys(): 
        print("Present, ", end =" ") 
        print("value =", dict[key]) 
    else: 
        print("Not present") 
  
dict = {'a': 100, 'b':200, 'c':300} 
  
key = 'b'
checkKey(dict, key) 
  
key = 'w'
checkKey(dict, key) 



List all Python Programs