Topics to be covered Introduction to dictionaries Creating dictionaries Modifying dictionaries Common dictionary methods Nested dictionaries
Introduction to dictionaries Dictionaries are used to store data types in key:value pairs. Keys must be unique(can’t have duplicates). Values can be of any data type( string,tuple,Int,list,dictionary ). Dictionaries are unordered, mutable(changeable)and don’t allow duplicate keys.
Modifying dictionaries Add new item : my_dict[‘country’]=‘India’ Update value : my_dict[‘age’]=16 Remove item : del my_dict[‘city’] Pop() method remove and returns value
Common dictionary methods my_dict.keys () #returns all keys. my_dict.values () #returns all values. my_dict.items () #returns key-value pairs. my_dict.update () #merges another dictionaries. my_dict.clear () # remove all items.