Exam-style question
Try this first
What does the following Python statement do? d["grass"].
- A.It accesses the value associated with the key "grass" in dictionary d
- B.It adds the key "grass" to every dictionary
- C.It changes the value associated with "grass" to the word d
- D.It deletes the dictionary d
Model answer
What a good answer should say
- It accesses the value associated with the key "grass" in dictionary d
Explanation
Why this works
In Python, a key in square brackets after a dictionary name is used to access the value associated with that key.
Common mistake
No common mistake is linked to this question yet.
