Python MCQ’s on Modules: SET 2

11. 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

Check Answer

Answer: a
In the “import modulename” form of import, the namespace of imported module becomes available to, but not part of, the importing module.

 

 

12. 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

Check Answer

Answer: b

In the “from-import” form of import, there may be name clashes because names of the imported identifiers aren’t specified along with the module name.

 

13. 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

Check Answer

Answer: c
In the “from-import” form of import, identifiers beginning with two underscores are private and aren’t imported.

 

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

Check Answer

Answer: d
In the “from-import” form of import, the imported identifiers (in this case factorial()) aren’t specified along with the module name.

 

15. 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

Check Answer

Answer: b
Python first searches for the local, then the global and finally the built-in namespace.

 

16. What is returned by math.ceil(3.4)?

a) 3

b) 4

c) 4.0

d) 3.0

Check Answer

Answer: b
The ceil function returns the smallest integer that is bigger than or equal to the number itself.

 

17. What is the value returned by math.floor(3.4)?

a) 3

b) 4

c) 4.0

d) 3.0

Check Answer

Answer: a
The floor function returns the biggest number that is smaller than or equal to the number itself.

 

18. What will be the output of print(math.copysign(3, -1))?

a) 1

b) 1.0

c) -3

d) -3.0

Check Answer

Answer: d
The copysign function returns a float whose absolute value is that of the first argument and the sign is that of the second argument.

 

19. What is displayed on executing print(math.fabs(-3.4))?

a) -3.4

b) 3.4

c) 3

d) -3

Check Answer

Answer: b
A negative floating point number is returned as a positive floating point number.

 

20. Is the output of the function abs() the same as that of the function math.fabs()?

a) sometimes

b) always

c) never

d) none of the mentioned

Check Answer

Answer: a
math.fabs() always returns a float and does not work with complex numbers whereas the return type of abs() is determined by the type of value that is passed to it.

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

Leave a Comment