Python MCQ’s on Modules: SET 1

1. Which of these definitions correctly describes a module?

a) Denoted by triple quotes for providing the specification of certain program elements

b) Design and implementation of specific functionality to be incorporated into a program

c) Defines the specification of how it is to be used

d) Any program that reuses code

Check Answer

Answer: b
The term “module” refers to the implementation of specific functionality to be incorporated into a program.

 

 

2. Which of the following is not an advantage of using modules?

a) Provides a means of reuse of program code

b) Provides a means of dividing up tasks

c) Provides a means of reducing the size of the program

d) Provides a means of testing individual parts of the program

Check Answer

Answer: c
The total size of the program remains the same regardless of whether modules are used or not. Modules simply divide the program.

 

3. Program code making use of a given module is called a ______ of the module.

a) Client

b) Docstring

c) Interface

d) Modularity

Check Answer

Answer: a
Program code making use of a given module is called the client of the module. There may be multiple clients for a module.

 

4. ______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.

a) Interface

b) Modularity

c) Client

d) Docstring

Check Answer

Answer: d
Docstring used for providing the specifications of program elements.

 

5. Which of the following is true about top-down design process?

a) The details of a program design are addressed before the overall design

b) Only the details of the program are addressed

c) The overall design of the program is addressed before the details

d) Only the design of the program is addressed

Check Answer

Answer: c
Top-down design is an approach for deriving a modular design in which the overall design.

 

6. In top-down design every module is broken into same number of submodules.

a) True

b) False

Check Answer

Answer: b
In top-down design every module can even be broken down into different number of submodules.

 

7. All modular designs are because of a top-down design process.

a) True

b) False

Check Answer

Answer: b
The details of the program can be addressed before the overall design too. Hence, all modular designs are not because of a top-down design process.

 

8. What will be the output of the following Python code?

#mod1

def change(a):

b=[x*2 for x in a]

print(b)

#mod2

def change(a):

b=[x*x for x in a]

print(b)

from mod1 import change

from mod2 import change

#main

s=[1,2,3]

change(s)

a) [2,4,6]

b) [1,4,9]

c)

[2,4,6] [1,4,9]

d) There is a name clash

Check Answer

Answer: d
A name clash is when two different entities with the same identifier become part of the same scope. Since both the modules have the same function name, there is a name clash.

 

9. Which of the following isn’t true about main modules?

a) When a python file is directly executed, it is considered main module of a program

b) Main modules may import any number of modules

c) Special name given to main modules is: __main__

d) Other main modules can import main modules

Check Answer

Answer: d
Main modules are not meant to be imported into other modules.

 

10. Which of the following is not a valid namespace?

a) Global namespace

b) Public namespace

c) Built-in namespace

d) Local namespace

Check Answer

Answer: b
During a Python program execution, there are as many as three namespaces – built-in namespace, global namespace and local namespace.

Page  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15      16 

Leave a Comment