Built-ins & Standard Library · Question 18 · Hard
Built-ins & Standard Library question 18
A program imports the same module helper from two different files. How many times is helper's top-level code executed in one run of the program?
- Once; later imports reuse the already loaded module
- Twice, once for each import statement
- Never, until one of its functions is called
- Once per function that the importing files use
Answer and explanation
Answer: A. Once; later imports reuse the already loaded module
Explanation: The first import runs the module's code and stores the module object in sys.modules. Every later import of the same name simply fetches that stored object.
Previous: Booleans are used in an isinstance check, in addition and inside sum. What… · Next: A defaultdict(int) is updated for one key, read for a second key and tested…
Practise built-ins & standard library
Try a fresh set of built-ins & standard library questions with an explanation after every answer, free and without signing up: Built-ins & Standard Library practice. Or sit a full placement mock test.
More built-ins & standard library questions
- sorted is given a key that returns a tuple, to rank students by marks (high to…
- itertools.groupby is applied directly to a string in which one letter appears…
- Booleans are used in an isinstance check, in addition and inside sum. What…
- A defaultdict(int) is updated for one key, read for a second key and tested…
- all, any and max are each given an empty list, with a default supplied to max…
More python practice
Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge