NEW
Font size
S
M
L
XL
WorksheetsPython Library-1
Total questions: 11
Worksheet time: 22mins
Name
Class
Date
1.
Which of these definitions correctly describes a module?
a)
a) Denoted by triple quotes for providing the specification of certain program elements
b)
b) Design and implementation of specific functionality to be incorporated into a program
c)
c) Defines the specification of how it is to be used
d)
d) Any program that reuses code
2.
Which of the following is not an advantage of using modules?
a)
a) Provides a means of reuse of program code
b)
b) Provides a means of dividing up tasks
c)
c) Provides a means of reducing the size of the program
d)
d) Provides a means of testing individual parts of the program
3.
Program code making use of a given module is called a ______ of the module.
a)
a) Client
b)
b) Docstring
c)
c) Interface
d)
d) Modularity
4.
______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.
a)
a) Interface
b)
b) Modularity
c)
c) Client
d)
d) Docstring
5.
Which of the following is not a valid namespace?
a)
a) Global namespace
b)
b) Public namespace
c)
c) Built-in namespace
d)
d) Local namespace
6.
Which of the following is false about “import modulename” form of import?
a)
a) The namespace of imported module becomes part of importing module
b)
b) This form of import prevents name clash
c)
c) The namespace of imported module becomes available to importing module
d)
d) The identifiers in module are accessed as: modulename.identifier
7.
Which of the following is false about “from-import” form of import?
a)
a) The syntax is: from modulename import identifier
b)
b) This form of import prevents name clash
c)
c) The namespace of imported module becomes part of importing module
d)
d) The identifiers in module are accessed directly as: identifier
8.
Which of the following isn’t true about main modules?
a)
a) When a python file is directly executed, it is considered main module of a program
b)
b) Main modules may import any number of modules
c)
c) Special name given to main modules is: __main__
d)
d) Other main modules can import main modules
9.
What will be the output of the following Python code?
from math import factorial
print(math.factorial(5))
a)
a) 120
b)
b) Nothing is printed
c)
c) Error, method factorial doesn’t exist in math module
d)
d) Error, the statement should be: print(factorial(5))
10.
A Python module is a file with the _____ file extension that contains valid Python code.
a)
.pymodule
b)
.py
c)
.module
d)
.pym
11.
Suppose a function called add() is defined in a module called adder.py. Which of the following code snippets correctly show how to import and use the add() function? Select all that apply.
a)
import add from adder
result = add(2, 3)
b)
from adder import add
result = add(2, 3)
c)
from adder import add
result = adder.add(2, 3)
d)
import add
result = adder.add(2, 3)
Reset
