Python Modules: MCQs On Modules In Python Programming

Python Modules. MCQs related to Modules in Python Programming.

 

Python Modules

 

 

What will be the output of the following Python function assuming that the random library has already been included ??

random.shuffle[1,2,24]

a) Randomized list containing the same numbers in any order
b) The same list, that is [1,2,24]
c) A list containing any random numbers between 1 and 24
d) Error

 

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)

 

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 global namespace

 

What will be the output of the following ??

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))

 

Python Modules

 

Which type of elements are accepted by random.shuffle() ??

a) strings
b) lists
c) tuples
d) integers

 

What will be the output of the following code ??

random.randrange(1,100,10)

a) 32
b) 67
c) 91
d) 80

 

Which of the statements about modules is false ??

a) In the “from-import” form of import, identifiers beginning with two underscores are private and aren’t imported
b) dir() built-in function monitors the items in the namespace of the main module
c) In the “from-import” form of import, all identifiers regardless of whether they are private or public are imported
d) When a module is loaded, a compiled version of the module with file extension .pyc is automatically produced

 

What does random.shuffle(x) do when x = [1, 2, 3] ??

a) error
b) do nothing, it is a placeholder for a function that is yet to be implemented
c) shuffle the elements of the list in-place
d) none of the mentioned

 

Python Modules

 

The randrange function returns only an integer value ??

a) True
b) False

 

Which of the following is false about “from-import” form of import ?? 

a) The syntax is: from modulename import identifier
b) This form of import prevents name clash
c) The namespace of imported module becomes part of importing module
d) The identifiers in module are accessed directly as: identifier

 

Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3})) ??

a) 0
b) 1
c) KeyError: 1
d) none of the mentioned

 

Both the functions randint and uniform accept _______ parameters ??

a) 0
b) 1
c) 3
d) 2

 

Python Modules

 

Which of the following is false about “import modulename” form of import ??

a) The namespace of imported module becomes part of importing module
b) This form of import prevents name clash
c) The namespace of imported module becomes available to importing module
d) The identifiers in module are accessed as: modulename.identifier

 

Which of the following will not be returned by random.choice(“1 ,”) ??

a) 1
b) (space)
c) ,
d) none of the mentioned

 

What will be the output ??

random.randrange(0,91,5)

a) 10
b) 18
c) 79
d) 95

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!