KnowledgeBoat Logo
|

Computer Science

Consider the given statements for creating dictionaries in Python:

D1 = { 'A' : 'CS' , 'B' : ' IP' }
D2 = { 'B' : 'IP', 'A' : 'CS ' }

Assertion (A): Output of print(D1==D2) is True.

Reasoning (R): Dictionary is a collection of key-value pairs. It is not a sequence.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Python Dictionaries

1 Like

Answer

Both A and R are true but R is not the correct explanation of A.

Explanation
The output of print(D1 == D2) is True. In Python, dictionaries are considered equal if they have the same keys and corresponding values, regardless of the order of the key-value pairs. Since D1 and D2 have the same keys with the same values, the comparison returns True. Dictionary is a collection of key-value pairs. It is not a sequence.

Answered By

1 Like


Related Questions