Explore topic-wise MCQs in Python.

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

1.

The module _______________ is a comparatively faster implementation of the pickle module.

A. cPickle
B. nPickle
C. gPickle
D. tPickle
Answer» B. nPickle
2.

Lambda functions cannot be pickled because:

A. Lambda functions only deal with binary values, that is, 0 and 1
B. Lambda functions cannot be called directly
C. Lambda functions cannot be identified by the functions of the pickle module
D. All lambda functions have the same name, that is, <lambda>
Answer» E.
3.

If __getstate__() returns _______________ the __setstate__() module will not be called on pickling.

A. True value
B. False value
C. ValueError
D. OverflowError
Answer» C. ValueError
4.

Which of the following cannot be pickled?

A. Functions which are defined at the top level of a module with lambda
B. Functions which are defined at the top level of a module with def
C. Built-in functions which are defined at the top level of a module
D. Classes which are defined at the top level of a module
Answer» B. Functions which are defined at the top level of a module with def
5.

The pickle module defines ______ exceptions and exports _______ classes.

A. 2, 3
B. 3, 4
C. 3, 2
D. 4, 3
Answer» D. 4, 3
6.

Which of the following functions raises an error when an unpicklable object is encountered by Pickler?

A. pickle.PickleError
B. pickle.PicklingError
C. pickle.UnpickleError
D. pickle.UnpicklingError
Answer» C. pickle.UnpickleError
7.

Which of the following functions can accept more than one positional argument?

A. pickle.dumps
B. pickle.loads
C. pickle.dump
D. pickle.load
Answer» B. pickle.loads
8.

The output of the following two Python codes is exactly the same.

A. True
B. FalseView Answer
Answer» B. FalseView Answer
9.

Which of the following functions can be used to find the protocol version of the pickle module currently being used?

A. pickle.DEFAULT
B. pickle.CURRENT
C. pickle.CURRENT_PROTOCOL
D. pickle.DEFAULT_PROTOCOL
Answer» E.
10.

Which of the following Python codes will result in an error?

A. >>> pickle.dumps(object)
B. >>> pickle.dumps(object, 3)
C. >>> pickle.dumps(object, 3, True)
D. >>> pickle.dumps(‘a’, 2)View Answer
E. >>> pickle.dumps(‘a’, 2)View Answer
Answer» D. >>> pickle.dumps(‘a’, 2)View Answer
11.

Pick the correct statement regarding pickle and marshal modules.

A. The pickle module supports primarily .pyc files whereas marshal module is used to sterilize Python objects
B. The pickle module keeps track of the objects that have already been sterilized whereas the marshal module does not do this
C. The pickle module cannot be used to sterilize user defined classes and their instances whereas marshal module can be used to perform this task
D. The format of sterilization of the pickle module is not guaranteed to be supported across all versions of Python. The marshal module sterilization is compatible across all the versions of Python
Answer» C. The pickle module cannot be used to sterilize user defined classes and their instances whereas marshal module can be used to perform this task
12.

To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.

A. dumps(), undumps()
B. loads(), unloads()
C. loads(), dumps()
D. dumps(), loads()
Answer» E.
13.

The process of pickling in Python includes:

A. conversion of a list into a datatable
B. conversion of a byte stream into Python object hierarchy
C. conversion of a Python object hierarchy into byte stream
D. conversion of a datatable into a list
Answer» D. conversion of a datatable into a list
14.

WHICH_OF_THE_FOLLOWING_FUNCTIONS_CAN_ACCEPT_MORE_THAN_ONE_POSITIONAL_ARGUMENT??$

A. pickle.dumps
B. pickle.loads
C. pickle.dump
D. pickle.load
Answer» D. pickle.load
15.

The pickle module defines ______ exceptions and exports _______ classes.$

A. 2, 3
B. 3, 4
C. 3, 2
D. 4, 3
Answer» C. 3, 2
16.

Which of the following functions raises an error when an unpicklable object is encountered by Pickler?$

A. pickle.PickleError
B. pickle.PicklingError
C. pickle.UnpickleError
D. pickle.UnpicklingError
Answer» B. pickle.PicklingError
17.

What is the output of the line of code shown below?

A.
B. 4
C. 5
Answer» B. 4