Python Scope and Modules important MCQs in English/Hindi | Nielit Notes | PDF
In this post, we cover all important Questions from the topic "Python Scope and Modules".
These MCQs will definitely help to pass IT and Computer students in any exam and interview that have Python Scope and Modules topic.
The Python Scope and Modules chapter covers the following topics:
1. Scope of objects and Names.
2. LEGB Rule.
3. Module Basics.
4. Module Files as Namespaces.
5. Import Model.
6. Reloading Modules.
After completion of the Python Scope and Modules unit, Students will be able to Understand the concept of modules and importing, loading and reloading of modules in programs.
Python Scope and Modules MCQs
Here are the 40 most important and frequently asked MCQs from the "Python Scope and Modules" topic.
1. Program code making use of a given module is called a ______ of the module.
a. Client
b. Docstring
c. Interface
d. Modularity
Ans. a
2. In top-down design every module is broken into same number of submodules.
a. True
b. False
Ans. b
3. What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday)?
tday=datetime.date.today()
print(tday.isoweekday())
a. 2
b. 3
c. wed
d. wednesday
Ans. b
4. All modular designs are because of a top-down design process.
a. True
b. False
Ans. b
5. 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
Ans. d
6. ______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.
a. Interface
b. Modularity
c. Client
d. Docstring
Ans. d
7. Which of the following is not a valid namespace?
a. Global namespace
b. Public namespace
c. Built-in namespace
d. Local namespace
Ans. b
8. 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
Ans. a
9. Program code making use of a given module is called a ______ of the module ??
a. Client
b. Docstring
c. Interface
d. Modularity
Ans.a. Client
10. What will be the output of the following Python ??
import random
random.choice(2,3,4)
a. An integer other than 2, 3 and 4
b. Either 2, 3 or 4
c. Error
d. 3 only
Ans.c. Error
11. What will be the output of the following ??
import sys
sys.argv
a. ‘ ‘
b. [ ]
c. [‘ ‘]
d. Error
Ans.c. [‘ ‘]
12. What does os.fchmod(fd, mode) do ??
a. change permission bits of the file
b. change permission bits of the directory
c. change permission bits of either the file or the directory
d. none of the mentioned
Ans.a. change permission bits of the file
13. Which of the following is not an advantage of using modules?
a. Provides a means of dividing up tasks
b. Provides a means of reuse of program code
c. Provides a means of reducing the size of the program
d. Provides a means of testing individual parts of the program
Ans. c
14. 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
Ans. b
15. 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
Ans. b
16. To obtain a list of all the functions defined under sys module, which of the following functions can be used ??
a. print(sys)
b. print(dir.sys)
c. print(dir[sys])
d. print(dir(sys))
Ans.d. print(dir(sys))
17. The function random.randint(4) can return only one of the following values. Which ??
a. 4
b. 3.4
c. error
d. 5
Ans.c. error
18. 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
Ans.c.
19. Which of the following functions does not accept any arguments ??
a. position
b. fillcolor
c. goto
d. setheading()
Ans.a. position
20. 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
Ans. c
21. To include the use of functions which are present in the random library, we must use the option:
a. random.h
b. import.random
c. import random
d. random.random
Ans. c
22. Program code making use of a given module is called a ______ of the module.
a. Client
b. Interface
c. Docstring
d. Modularity
Ans. a
23. ______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.
a. Client
b. Interface
c. Docstring
d. Modularity
Ans. c
24. What will be the output of the following Python code if the system date is 18th August, 2016?
tday=datetime.date.today()
print(tday.month())
a. 8
b. 08
c. Aug
d. August
Ans. a
25. The output of the following Python code is either 1 or 2.
import random
random.randint(1,2)
a. True
b. False
Ans. a
26. Point out the error (if any) in the code shown below if the system date is 18th June, 2017?
tday=datetime.date.today()
bday=datetime.date(2017,9,18)
till_bday=bday-tday
print(till_bday)
a. 3 months, 0:00:00
b. 90 days, 0:00:00
c. 3 months 2 days, 0:00:00
d. 92 days, 0:00:00
Ans. d
27. All modular designs are because of a top-down design process.
a. True
b. False
Ans. b
28. The value returned when we use the function isoweekday() is ______ and that for the function weekday() is ________ if the system date is 19th June, 2017 (Monday).
a. 0,0
b. 0,1
c. 1,0
d. 1,1
Ans. c
29. What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?
tday=datetime.date.today()
print(tday.weekday())
a. 0
b. 1
c. 6
d. 7
Ans. c
30. What will be the output of the following Python code?
import random
random.choice([10.4, 56.99, 76])
a. Error
b. 56.99 only
c. Either 10.4, 56.99 or 76
d. Any number other than 10.4, 56.99 and 76
Ans. c
31. Which of the following is not a valid namespace ??
a. Global namespace
b. Public namespace
c. Built-in namespace
d. Local namespace
Ans.b. Public namespace
32. Which of the following is equivalent to random.randint(3, 6) ??
a. random.choice([3, 6])
b. random.randrange(3, 6)
c. 3 + random.randrange(3)
d. 3 + random.randrange(4)
Ans. d. 3 + random.randrange(4)
33. 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))
Ans. d
34. What is the interval of the value generated by the function random.random(), assuming that the random module has already been imported ??
a. (0,1)
b. (0,1]
c. [0,1]
d. [0,1)
Ans.d. [0,1)
35. 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
Ans. c
36. Which of the following isn’t true about main modules ??
a. When a python file is directly executed, it is considered the 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
Ans.d. Other main modules can import main modules
37. 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
Ans. b
38. The output of the following Python code is either 1 or 2 ??
import random
random.randint(1,2)
a. True
b. False
Ans.a. True
39. What will be the output of code ??
import turtle
t=turtle.Pen()
t.goto(300,9)
t.position()
a. 300.00, 9.00
b. 9, 300
c. 300, 9
d. 9.00, 300.00
Ans.a. 300.00, 9.00
40. The output of the functions len(“abc”) and sys.getsizeof(“abc”) will be the same ??
a. True
b. False
Ans.b. False
No comments: