-
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'
-
What is the length of an empty dictionary?
0
-
Write the Python statement to create an entry in the
students dictionary for a student
with student ID '0123456' whose name is 'John Smith'.
students['0123456'] = 'John Smith'
-
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
-
What does the length of a dictionary mean?
the number of key - value pairs in the dictionary
-
Write the Python expression you would use to get the number of entries in a dictionary
named students.
len(students)
-
Can dictionary entries be accessed by their position?
no. entries in a dictionary have no definite position