What will be the output of the following Python code? P = ["A", "B"] Q = (0,…

2026

What will be the output of the following Python code?
P = ["A", "B"]
Q = (0, 1)
R = dict.fromkeys(P, Q)
print(R)

  1. A.

    {'A': (0, 1), 'B': (0, 1)}

  2. B.

    {'A': 0, 'B': 1}

  3. C.

    {'A': 1, 'B': 0}

  4. D.

    ['A': (0, 1), 'B': (0, 1)]

Attempted by 169 students.

Show answer & explanation

Correct answer: A

The code creates a dictionary using dict.fromkeys() with keys from list P and value Q. Since Q is the tuple (0, 1), both keys 'A' and 'B' map to this specific immutable tuple object. The output is {'A': (0, 1), 'B': (0, 1)}.

Explore the full course: Rssb Senior Computer Instructor