Computer Science
What is printed by the following statements ?
D1 = {"cat":12,"dog":6,"elephant":23,"bear":20}
print("dog" in D1)
- True
- False
- Error
- 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
Which of the following is correct with respect to above Python code ?
d = {"a" : 3,"b" : 7}- a dictionary d is created.
- a and b are the keys of dictionary d.
- 3 and 7 are the values of dictionary d.
- All of these.
What would the following code print ?
d = {'spring':'autumn','autumn':'fall','fall':'spring'} print(d['autumn'])- autumn
- fall
- spring
- Error
What is printed by the following statements ?
D1 = {"cat":12,"dog":6,"elephant":23,"bear":20} print(25 in D1)- True
- False
- Error
- None
What will be the result of the following code ?
d1 = {"abc":5,"def":6,"ghi":7} print(d1[0])- abc
- 5
- {"abc":5}
- Error