KnowledgeBoat Logo
|

Informatics Practices

Consider the following dictionary

Book = {1 : "Informatics Practices", 
        2 : "Computer Science ",
        3 : "Information Technology"}

Jaya executes statement: 2 in Book

Assertion (A): For the above dictionary Book, the output of the statement 2 in Book is True.

Reasoning (R): For Dictionary, the ‘in’ and ‘not in’ operators return True or False.

  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 and R is the correct explanation of A.

Explanation
The statement 2 in Book checks if the key 2 exists in the dictionary Book. Since 2 is a key in the dictionary with the value "Computer Science ", the statement returns True. The in and not in operators in Python dictionaries return True or False depending on whether the specified key exists in the dictionary or not.

Answered By

2 Likes


Related Questions