ProgrammingHardAccenture · Cognizant · Python

What does the following Python 3 code print? d = {"a": 1, "b": 2} print(*d)

  1. A. a 1 b 2
  2. B. {'a', 'b'}
  3. C. ('a', 'b')
  4. D. a b

Correct answer: D. a b

Unpacking a dict with * iterates over its keys, so print receives 'a' and 'b' as two separate arguments.

More Python Programming questions

Exams that ask this topic