Using Python Libraries || Multiple Choice Questions || Class 12
1. What will be the output of the following Python code?
from math import factorial
print (math.factorial (5))
(a) 120
(b) Nothing is printed
(c) Error, method factorial doesn't exist in math module
(d) Error, the statement should be: print(factorial(5))
2. What is the order of namespaces in which Python looks for an identifier?
(a) Python first searches the global namespace, then the local namespace and finally the built-in namespace
(b) Python first searches the local namespace, then the global namespace and finally the built-in namespace
(c) Python first searches the built-in namespace, then the global namespace and finally the local namespace
(d) Python first searches the built-in namespace, then the local namespace and finally the gloab namespace
3. Which of the following is not a valid namespace?
(a) Global namespace
(b) Public namespace
(c) Built-in namespace
(d) Local namespace
4. What will be the output of the following Python code?
#modules
def change (a):
b=[x * 2 for x in a]
print (b)
#module 2
def change (a):
b= (x*x for x in a)
print (b)
from module import change
from module2 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 cash
5. What is the output of the function shown below (random module has already been imported)?
random.choice('sun')
(a) sun
(b) u
(c) either s, u or n
(d) error
6. What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code?
import random
AR = [ 20, 30, 40, 50, 60, 70]
FROM = random.randint (1, 3)
TO = random.randint (2, 4)
for K in range (FROM, TO+1):
print (AR(K), end = "#")
(a) 10#40#70#
(b) 30#40#50#
(c) 50#60#70#
(d) 40#50#70#
7. Which of the statements is used to import all names from a module into the current calling module?
(a) import
(b) from
(c) import *
(d) dir()
8. Which of the variables tells the interpreter where to locate the module files imported into a program?
(a) local
(b) import variable
(c) PYTHONPATH
(d) current
9. Which of the following date class function returns the current system date?
(a) day()
(b) today()
(c) month()
(d) year()
10. What is the range of values that random.random() can return?
(a) [0.0, 1.0]
(b) (0.0, 1.0]
(c) (0.0, 1.0)
(d) [0.0, 1.0)
11. A .py file containing constants/variables, classes, functions etc. related to a particular task and can be used in other programs is called
(a) module
(b) library
(c) classes
(d) documentation
12. The collection of modules and packages that together cater to a specific type of applications or requirements, is called ____.
(a) module
(b) library
(c) classes
(d) documentation
13. An independent triple quoted string given inside a module, containing documentation related information is a ____.
(a) Documentation string
(b) docstring
(c) dstring
(d) stringdoc
14. The help
(a) constants
(b) functions
(c) classes
(d) docstrings
15. Which command(s) modifies the current namespace with the imported object name?
(a) import <module>
(b) import <module1>, <module2>
(c) from <module> import <object>
(d) from <module> import *
16. Which command(s) creates a separate namespace for each of the imported module?
(a) import <module>(b) import <module1>, <module2>
(c) from <module> import <object>
(d) from <module> import *
17. Which of the following random module functions generates a floating point number?
(a) random()
(b) randint()
(c) uniform()
(d) all of these
18. Which of the following random module functions generates an integer?
(a) random()
(b) randint()
(c) uniform()
(d) all of these
19. Which file must be a part of a folder to be used as a Python package?
(a) package.py
(b) __init__.py
(c) __package__.py
(d) __module.py__
20. A Python module has ___ extension.
(a) .mod
(b) .imp
(c).py
(d) .mp
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )