Instruction
All right, it's time to wrap things up!
-
Dictionaries are defined within curly braces:
phonebook = {'Mary': '8349374', 'Anne': '7439834', 'John': '3472983'} -
Dictionary elements are accessed with keys in square brackets:
phonebook['Mary']
-
To add or update a dictionary element, use the following notation:
phonebook['Mary'] = '3243563' phonebook['Jack'] = '3423457'
-
To delete a dictionary element, use:
del phonebook['Mary']
-
To iterate over a dictionary, use:
for key, value in phonebook.items(): print(key, '=', value)
-
Dictionaries can be used as function arguments. They can also be returned from functions.
Time for a short quiz!
Exercise
Click to continue.



