Lab 10: Knowledge Check
These questions check your knowledge of concepts from this lab. Use the button at the bottom to show your answers once you've attempted them.
-
True or false: The keys of a dictionary can be accessed by putting their associated value in square brackets after the dictionary.
True False -
If we run the following code, what is final the value of the variable
taxes
?taxes = { 'income': 50000 } taxes['taxable'] = taxes['income'] taxes['income'] += 10000 taxes['tax'] = taxes['taxable'] * 0.1
- { 'income': 50000, 'taxable': 50000, 'tax': 5000 }
- { 'income': 60000, 'taxable': 50000, 'tax': 5000 }
- { 'income': 60000, 'taxable': 60000, 'tax': 5000 }
- { 'income': 60000, 'taxable': 60000, 'tax': 6000 }
-
Which of the following statements are true about dictionaries? (pick one or more)
-
You can use
.append
to add key/value pairs. -
You can use
.insert
to add key/value pairs. - You can use square brackets to access the value associated with a particular key.
-
You can use
.get
to access the value associated with a particular key. -
You can use
.pop
to remove a key/value pair if you only know the value. -
The
in
operator checks keys and values. -
You can use
dict[key] = value
to assign a value to a dictionary slot specified using a key, even if that key isn't in the dictionary yet.
-
You can use
Table of Contents
- Lab 10 Home
- Cheat Sheet: Lists & Dictionaries
- Part 1: Exercises
- Part 2: Ironman data
- Knowledge Check