Q. What happens when Python encounters an import statement in a program? What would happen, if there is one more import statement for the same module, already imported in the same program?


Answer =


When Python encounters an import statement it does the following:-

(i) The code of imported module is interpreted and executed.
(ii) Defined functions and variables created in the module are now available to the program that imported module.
(iii) For imported module, a new namespace is setup with the same name as that of the module.

Any duplicate import statement for the same module in the same program is ignored by Python.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post