Python Dictionaries
Python dictionary is a collection of data and it is stored in the form of key:value pairs. Dictionaries are ordered, changeable and duplicates are not allowed. Dictionary is case sensitive.
Creating Python Dictionaries:
Dictionaries are created by placing the keys:values separated by commas inside the curly brackets.
Adding the elements to dictionary:
If the key is already present it’ll get updated but if the key is not there, the pair will get added to the dictionary.
Adding elements to the dictionary
Nested dictionaries:
Inbuilt Python Dictionary Methods:
copy( )- Returns a copy of the dictionary
clear( )- Removes all the elements of dictionary
get( )- Returns the value of that particular key
keys( )- Returns a list of all the keys in the dictionary
values( )- Returns a list of all the values in the dictionary
pop( )- Removes the value of the specified key
Update( )- Updates the dictionary with key:value pairs
0 Comments