A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

1. Which of the following statements create a dictionary?
a. d = {}
b. d = {“john”:40, “peter”:45}
c. d = {40:”john”, 45:”peter”}
d. All of the mentioned
View Answer Report Discuss Too Difficult!
Answer: (d).All of the mentioned

2. Read the code shown below carefully and pick out the keys?
d = {"john":40, "peter":45}
a. “john”, 40, 45, and “peter”
b. “john” and “peter”
c. 40 and 45
d. d = (40:”john”, 45:”peter”)
View Answer Report Discuss Too Difficult!
Answer: (b).“john” and “peter”

3. What will be the output?
d = {"john":40, "peter":45}"
john" in d
a. True
b. False
c. None
d. Error
View Answer Report Discuss Too Difficult!
Answer: (a).True

4. What will be the output?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
a. True
b. False
c. None
d. Error
View Answer Report Discuss Too Difficult!
Answer: (b).False

5. What will be the output?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a. True
b. False
c. None
d. Error
View Answer Report Discuss Too Difficult!
Answer: (d).Error

6. What is the output?
d = {"john":40, "peter":45}
d["john"]
a. 40
b. 45
c. “john”
d. “peter”
View Answer Report Discuss Too Difficult!
Answer: (a).40

7. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use
a. d.delete(“john”:40)
b. d.delete(“john”)
c. del d[“john”].
d. del d(“john”:40)
View Answer Report Discuss Too Difficult!
Answer: (c).del d[“john”].

8. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?
a. d.size()
b. len(d)
c. size(d)
d. d.len()
View Answer Report Discuss Too Difficult!
Answer: (b).len(d)

9. What will be the output?
d = {"john":40, "peter":45}
print(list(d.keys()))
a. [“john”, “peter”].
b. [“john”:40, “peter”:45].
c. (“john”, “peter”)
d. (“john”:40, “peter”:45)
View Answer Report Discuss Too Difficult!
Answer: (a).[“john”, “peter”].

10. Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?
a. Since “susan” is not a value in the set, Python raises a KeyError exception
b. It is executed fine and no exception is raised, and it returns None
c. Since “susan” is not a key in the set, Python raises a KeyError exception
d. Since “susan” is not a key in the set, Python raises a syntax error
View Answer Report Discuss Too Difficult!
Answer: (c).Since “susan” is not a key in the set, Python raises a KeyError exception

Page 1 of 13