KnowledgeBoat Logo
|

Computer Science

What is printed by the following statements ?

D1 = {"cat":12,"dog":6,"elephant":23,"bear":20} 
print("dog" in D1)
  1. True
  2. False
  3. Error
  4. None

Python Dictionaries

6 Likes

Answer

True

Reason — in operator is used to check whether a certain key is in the dictionary or not. It is also called containment check. It returns a boolean value.
Here, the expression "dog" in D1 will print true, since D1 contains "dog" key.

Answered By

2 Likes


Related Questions