Mega Code Archive

 
Categories / Python Tutorial / Dictionary
 

Dictionary Syntax

Dictionaries are written like  this:  phonebook = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'}  Dictionaries consist of pairs (called items) of keys and their corresponding values.  Each key is separated from its value by a colon (:), the items are separated by commas, and the  whole thing is enclosed in curly braces.  An empty dictionary (without any items) is written with just two curly braces, like this: {}.  Keys are unique within a dictionary (and any other kind of mapping), while values may not be.