In [1]:
d = {'John': '111-2222', 'Peter': '333-3333'}
In [2]:
d['John']
Out[2]:
'111-2222'
In [3]:
d['Peter']
Out[3]:
'333-3333'
In [4]:
d['james']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-b531da030323> in <module>
----> 1 d['james']

KeyError: 'james'
In [5]:
'james' in d
Out[5]:
False
In [6]:
'John' in d
Out[6]:
True
In [7]:
d['James'] = '999-9999'
In [10]:
d['James']
Out[10]:
'000-0000'
In [9]:
d['James'] = '000-0000'
In [13]:
for key in d:
    print(key,'\t',d[key])
John 	 111-2222
Peter 	 333-3333
James 	 000-0000
In [14]:
students = {'John' : {'major':'Computer Science', 'gpa': 3.5, 'phone': ['11','22']},
            'Peter': {'major': 'Math', 'gpa': 4.0, 'phone': ['33']}
           }
In [17]:
students['John']
Out[17]:
{'major': 'Computer Science', 'gpa': 3.5, 'phone': ['11', '22']}
In [18]:
students['John']['major']
Out[18]:
'Computer Science'
In [19]:
students['John']['phone'][0]
Out[19]:
'11'