You create a dictionary with curly braces, followed by a key and a value — just like a JSON object:
capitals = {'Ghana': 'Accra', 'Nigeria': 'Abuja', 'Cameroon': 'Yaounde'}Dictionary Operators
[]—capitals['Ghana']— returns the value associated with the keyGhana, otherwise it’s an error.in—'Ghana' in capitals— returnsTrueif the keyGhanais in the dictionary,Falseotherwise.del—del capitals['Ghana']— removes the entryGhanafrom the dictionary.
Dictionary Methods
keys—capitals.keys()— returns the keys of the dictionary in adict_keysobject.values—capitals.values()— returns the values of the dictionary in adict_valuesobject.items—capitals.items()— returns the key-value pairs in adict_itemsobject.get—capitals.get('Ghana')— returns the value associated with the keyGhana,Noneotherwise.get—capitals.get('Ghana', 'Not Found')— returns the value associated with the keyGhana,'Not Found'otherwise.