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.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- 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
Consider the given two statements:
Statement 1: t1 = tuple('python')
Statement 2: t1[4] = 'z'Assertion (A): The above code will generate an error.
Reasoning (R): Tuple is immutable by nature.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): In Python, tuple is an immutable sequence of data.
Reasoning (R): Immutable means that any change or alteration in data is mentioned in the same place. The updated collection will use the same address for its storage.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): Dictionaries are enclosed within curly braces { }.
Reasoning (R): The key-value pairs are separated by commas (,).
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): The pop() method can be used to delete elements from a dictionary.
Reasoning (R): The pop() method deletes the key-value pair and returns the value of deleted element.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.