← Quiz: Python Dictionaries: all 15 questions
Quiz: Python Dictionaries · Question 13 of 15
What does this print? (code)
What does this print?
squares = {n: n * n for n in range(1, 4)}
print(squares)
- A.{1: 1, 2: 4, 3: 9}
- B.{1: 2, 2: 4, 3: 6}
- C.[1, 4, 9]
- D.{0: 0, 1: 1, 2: 4, 3: 9}
Answer & explanation
Correct answer: {1: 1, 2: 4, 3: 9}
A dictionary comprehension builds key: value pairs; range(1, 4) gives 1, 2, 3.
Can you get the rest right without peeking?
Take the timed Quiz: Python Dictionaries quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →