CBSE Class 11 Informatics Practices
Question 17 of 40
Practice Paper — Question 17
Back to all questions 17
Question 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.
- 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.
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.