The creation, indexing, operators, and functions of dictionaries in Python. It also covers string methods such as insertion and update. examples of each operation and function. useful for students learning Python programming and specifically dictionaries.
Insertion method #insertion can be done by SubscriptNotation dic = {'Fruit': 'lichi', 'friend': 'Shubham'} dic["FvtNo"] =3 #it will insert new key and value pair dic["FvtNo"] =33 #it will update existing value
Update method #The update() method updates the dictionary with the elements from another dictionary object dic = {'Fruit': 'lichi', 'friend': 'Shubham'} dic2 ={11:"eleven",12:"twelve"} dic.update(dic2) print(dic) #output {'Fruit': 'lichi', 'friend': 'Shubham', 'FvtNo': 33, 11: 'eleven', 12: 'twelve'}
Get method dic2={'Fruit': 'lichi', 'friend': 'Shubham', 'FvtNo': 3, 11: 'eleven'} print(dic2.get("Fruit"))#output=’lichi print(dic2.get("Colour","Blue")) #if key does not exist already provide 2nd arg value