Dictionary in Python
# how to create blank dictionary dictionary = {} print(dictionary) # declare dictionary with key and value dictionary = {"fname": "avni","mname":"singh","lname":"rathor"} print(dictionary) # accessing key and value from dictionary for key in dictionary: print(key) print(dictionary[key]) # accessing key and value with items method for key,value in dictionary.items(): print(key,value) # value can also be fetched from get method print(dictionary["fname"]) print(dictionary.get("fname")) # now will add key and value in dictionary . dictionary["age"] = "31" print(dictionary) # now removing item fname from dictionary dictionary.pop("fname") print(dictionary) # del keyword can also be used del del dictionary["lname"] print(dictionary) # can clear dictionary with clear function dictionary.clear() print(dictionary) # dict constructior