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?

  1. Once; later imports reuse the already loaded module
  2. Twice, once for each import statement
  3. Never, until one of its functions is called
  4. 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

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