Explore topic-wise MCQs in Python.

This section includes 3 Mcqs, each offering curated multiple-choice questions to sharpen your Python knowledge and support exam preparation. Choose a topic below to get started.

1.

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
Answer» D. Since susan is not a key in the set, Python raises a syntax error
2.

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()
Answer» C. size(d)
3.

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)
Answer» D. del d( john :40)