logo

AQA A-Level Computer Science practice

What does the following Python statement do? d["grass"]

Try the question first, then check the answer and practise the same topic again.

At a glance

MCQ

Type

practice

Style

Topic

Dictionaries

Exam-style question

Try this first

What does the following Python statement do? d["grass"].

  1. A.It accesses the value associated with the key "grass" in dictionary d
  2. B.It adds the key "grass" to every dictionary
  3. C.It changes the value associated with "grass" to the word d
  4. D.It deletes the dictionary d

Answer and explanation

Concise answer

It accesses the value associated with the key "grass" in dictionary d

Why this is correct

In Python, a key in square brackets after a dictionary name is used to access the value associated with that key.

Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions