Computer Science
How are following import statements different ?
(a) import X
(b) from X import *
(c) from X import a, b, c
Answer
(a) import X — This statement is used to import entire module X. All the functions are imported in a new namespace setup with same name as that of the module X. To access one of the functions, we have to specify the name of the module (X) and the name of the function, separated by a dot. This format is called dot notation.
(b) from X import * — This statement is used to import all the items from module X in the current namespace. We can use all defined functions, variables etc from X module, without having to prefix module's name to imported item name.
(c) from X import a, b, c — This statement is used to import a, b, c objects from X module in the current namespace. We can use a, b, c objects from X module, without having to prefix module's name to imported item name.