-
What are the entries in a dictionary?
key - value pairs
-
Are dictionaries sequences?
no
-
If I had a dictionary of email addresses named emails,
what would I write to get the email for the person named 'Chris'?
emails['Chris']
-
Write the Python statement to create an empty dictionary named
empty.
empty = {}
-
If I wanted to add the email address 'dave.souza@gmail.com' to the dictionary
emails using the key 'Dave', what Python statement
would I write?
emails['Dave'] = 'dave.souza@gmail.com'
-
Write the Python statement to change the value for 'Dave' in the dictionary above
to 'dave.souza@hotmail.com'
emails['Dave'] = 'dave.souza@hotmail.com'
-
Write the Python expression you would use to test whether the
students dictionary contains
an entry for a student with the ID '0123456'.
'0123456' in students
-
Write the Python expression you would use to test whether the
students dictionary DOES NOT contain
an entry for a student with the ID '0123456'.
'0123456' not in students
-
Write the Python statement you would use to delete the entry in the
students dictionary with
key value '0123456'.
del students['0123456']
-
What would happen if you tried to delete a dictionary entry using a key
that was NOT in the dictionary?
you would get a KeyError exception